java - How do I pass variables into a new android activity, with the ability to use them throughout the class? -


i'm trying pass variable activity, getting null object reference.

my intent declaration makes use of putextra()

public void launch_test(view view) {     playsound.start();     intent launch_test = new intent(this, test.class);         launch_test.putextra("num_rows", 4);         launch_test.putextra("num_cols", 4);     startactivity(launch_test); } 

and activity class (test) calls extras,

public class test extends activity { intent launch_test = getintent(); bundle extras = launch_test.getextras();  int num_rows = launch_test.getintextra("num_rows", 0); int num_cols = launch_test.getintextra("num_cols", 0);  button buttons[][] = new button[num_rows][num_cols];  etc... 

but i'm getting null object reference when try run in emulator.

i assume use if statement check nulls, android studio isn't letting me use if statement in area of code. if place if statement oncreate function, won't able use variables throughout class, way to.

i'm new @ android coding, i'm sorry if there's confusion!

if u want use code , please rectify use : extras.getintextra instead of launch_test.getintextra


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -