开发者

Accesing a variable from another file

开发者 https://www.devze.com 2023-02-25 19:05 出处:网络
I am using a 开发者_如何转开发string variable in aclass 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

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 AdminPwdParsing.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消