android - Aessing public variable in java -


i have create public variable in fouractivity , access in finalactivity class value of variable show 0. have been create getrandomnumber function in fouractivity class return integer.

public int i; i=getrandomnumber();    // accessing variable in finalactivity class through way fouractivity fouractivity=new fouractivity(); int randomnumber=fouractivity.i; toast.maketext(finalactivity.this,"random number" +randomnumber ,toast.length_short).show(); 

i not static, therefore when write :

fouractivity fouractivity=new fouractivity(); int randomnumber=fouractivity.i; 

you uninitialized value of i new fouractivity instance created.

i=getrandomnumber(); updated difference isntance of fouractivity.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -