-2
我有這樣一段代碼,它是造成NullPointerException異常的Android清單NullPointerException異常
private List<Player> playerList;
private List<String> playerName;
Bundle b = getIntent().getExtras();
this.currentGame = b.getParcelable("created_tournament");
playerList = currentGame.getPlayers();
for (int i = 0; i < playerList.size(); i ++) {
this.playerName.add(this.playerList.get(i).getName());
Log.d(TAG, "Input was not a number!" + this.playerList.get(i).getName());
}
與playerList從Parcelable對象採取List<Player>
和playerName
是List<String>
。
從理論上講,應該this.playerName.add(this.playerList.get(i).getName());
因爲Log.d(TAG, "Input was not a number!" + this.playerList.get(i).getName());
作品能正常工作,而不會造成任何異常
任何想法?
它總是一個好主意,指出該行尋求幫助時導致異常。 –