【发布时间】:2011-11-20 07:26:42
【问题描述】:
我有这段代码,它导致 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 是 List<Player> 取自 Parcelable 对象,playerName 是 List<String>。
理论上,this.playerName.add(this.playerList.get(i).getName()); 应该可以工作,因为Log.d(TAG, "Input was not a number!" + this.playerList.get(i).getName()); 可以正常工作而不会导致任何异常
有什么想法吗?
【问题讨论】:
-
在寻求帮助时指出哪一行导致异常总是一个好主意。
标签: android arraylist nullpointerexception