I am using a 开发者_如何转开发string variable in a class Abc , but i am not able to acces it in another class xyz.the value of variable is showing null. here is my skeleton of the code
public class Abc extends Activity
{
static String strNew ;
.....
}
public class xyz extends Activity
{
Log.i("strPassword","strPassword is:"+Abc.strNew);
.....
}
the value of strNew is showing null , how can i overcome this problem.please help me out thanks in advance
You variable strNew is defined in the class Abc
and not AdminPwdParsing
. So you should use Abc
instead of AdminPwdParsin
g.
public class xyz extends Activity
{
Log.i("strPassword","strPassword is:"+ Abc.strNew);
.....
}
Additionally you have declared the variable strNew but you have never set a value. So the actual value is null. Somewhere in you code you have to set a value to your String:
strNew = "foo bar";
Another problem is that the visibility of your variable is package private. So it can only be accessed from within the same package. Set the visibility of the variable to public if you want to access it from everywhere.
精彩评论