I am creating the app where the players put their names into a program, the program sends their names to the next activity in a String array, and the next program puts the array into a list an then shuffles it. For some reason, everytime I try to use the.setText function, the app gets a nullpointerexception error. I have tested the list with a toast to verify that it is not null, which it is not. Any suggestions?
endInstructions = (Button)findViewById(R.id.buttonEndInstructions);
player = (TextView)findViewById(R.id.textViewPlayerName);
endInstructions.setOnClickListener(this);
Bundle ext = getIntent().getExtras();
int numberOfPlayers= ext.getInt("numberofplayers");
String[] sarray = ext.getStringArray("namearray");
names = Arrays.asList(sarray);
Collections.shuffle(names);
Toast.makeText(this, names.get(0), Toast.LENGTH_SHORT).show();
//player.setText(names.get(0));
Thanks in advance!
There are not a million solutions…
Player is null, you can check that by testing:
What does that mean? Probably that your current layout does not contains a textview called “textViewPlayerName”
Please double check your xml layout or be sure that you used setContentView before 😉
Edit: as endInstructions is not null regarding your code, you corretly used setContentView before…