Note that there are some explanatory texts on larger screens.

plurals
  1. POThe value of a variable in one class is recieved as null in another when called in java
    primarykey
    data
    text
    <p>I want to use the value of a string variable in one class into another...</p> <p>But when i do so by creating an object in the calling class of the called class, i get the value as null.</p> <p>I tried searching on the net and stack overflow and went through some similar answers,but the solutions to them were specific to those questions.So m asking again.</p> <p>here are the 2 classes -</p> <p>1st one is the class from which i want to use the variable. class is - SelectedClass variable i want to use in another class - SelectedClass( a string)</p> <p>2nd class is FEa.I want to use the value of the variable "SelectedClass" from the 1st class.</p> <p>CLASS 1(SelectedClass)-</p> <pre><code>package com.attendance_trial.nirmik; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class SelectClass extends ListActivity { public String classes2[] = {"FEa","FEb","SEa","SEb"}; String SelectedClass; @Override public void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); String SelectedClass = classes2[position]; try { Class MyClass = Class.forName("com.attendance_trial.nirmik." + SelectedClass); Intent myintent = new Intent(SelectClass.this,MyClass); startActivity(myintent); } catch(ClassNotFoundException cnf) { cnf.printStackTrace(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO Auto-generated method stub setListAdapter(new ArrayAdapter&lt;String&gt;(SelectClass.this, android.R.layout.simple_list_item_1, classes2)); } </code></pre> <p>}</p> <p>CLASS 2 (FEa) -</p> <pre><code>package com.attendance_trial.nirmik; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class FEa extends Activity implements View.OnClickListener { SelectClass sc = new SelectClass(); //Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,bSend; Button bSend; TextView tvDisp; String acc=""; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.fea); initialise(); } private void initialise()//initialise all buttons etc { bSend = (Button) findViewById (R.id.BtnSendMsg); bSend.setOnClickListener(this); tvDisp=(TextView) findViewById (R.id.TxtViewDisplay); } public void onButtonClick(View v) { // TODO Auto-generated method stub Button theButton = (Button)v; String chk = theButton.getText().toString(); if(chk.contentEquals("1")||chk.contentEquals("2")||chk.contentEquals("3")||chk.contentEquals("4")||chk.contentEquals("5") ||chk.contentEquals("6")||chk.contentEquals("7")||chk.contentEquals("8")||chk.contentEquals("9")) { acc = acc + "0" + chk; } else { acc = acc +chk; } tvDisp.setText("String Is:" + acc); }//method end @Override public void onClick(View v2) { // TODO Auto-generated method stub int retid = v2.getId(); if(retid == R.id.BtnSendMsg ) //send button clicked { String msg = sc.SelectedClass + "2210"+ acc; Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg); startActivity(emailIntent); } } </code></pre> <p>}//main end</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload