android - Retrieving String From Java Class -


i new java / android programming , have been following tutorials / reading. have 2 classes called mainactivity , homeactivity, mainactivity user logs in , homepageactivity opened via intent if login correct.

the username passed through edit text have used following code in main class

string currentuser = edittextusername.gettext().tostring(); public string getcurrentuser () {     return currentuser; } 

and in homepage class

mainactivity testing = new mainactivity(); string x = testing.getcurrentuser(); currentusername.settext(x); 

this seems should work me, how ever when launching application crashes, , without lines of code in main activity works fine

any ideas im doing wrong here guys

the string may null during setting textview check before setting textview

string currentuser = edittextusername.gettext().tostring();                             public string getcurrentuser ()                             {                                if(currentuser.length>0&&currentuser!="")                                       return currentuser;                                else return "empty";                               } string x = testing.getcurrentuser();           currentusername.settext(""+x); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -