I am trying to go through an object which has an array within it containing names and numbers of -
public void showPlayerGameList(){
playerTextView = findViewById(R.id.aPlayerBox);
for(PlayerDetails aPlayer : playerListGame.myPlayers) {
playerTextView.append(aPlayer.name + "\n");
}
}
}
But I get the following error:
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.example.android.footysortit.PlayerDetails.name' on a null object reference
The way I am adding my player which is an object of PlayerDetails (which just contains a 2x String and an Int):
if(phone.moveToFirst()) {
PlayerDetails player = new PlayerDetails(); //TODO turn this into a loop to add each player the user picks and then display it
player.name = phone.getString(phone.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// player.number =phone.getString(phone.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
playerListGame.addPlayer(player);
The idea is for the user to pick a contact and their name displays within a list but they can pick different contacts each time and each contact should be added to the list.
Any ideas?
Thank you