ImageViewをArrayListに格納する背後にあるロジックに問題があります。
私が開発しているアプリケーションは、ゲーム内のプレーヤーのステータスを追跡します。ユーザーは最初にPlayerオブジェクト(ステータス文字列とそれに伴うステータス画像を追跡します)をArrayList(それらすべてを追跡します)に追加します。次に、すべてのプレーヤーを送信すると、ボタン(プレーヤーのプロファイルを表示するため)、ImageView(ステータスを表すアイコン)、およびTextView(プレーヤーのステータス文字列を含む)を含む、各プレーヤーのTableRowを膨らませる画面がポップアップ表示されます。価値)。
ボタンや各プレイヤーのプロフィールの読み込みに問題はありません。この問題は、dialog_select_icon.xml、特にImageViewArrayListから「selectstatus」GUIをロードするときに発生します。NullPointerExceptionが発生しますが、ボタンと基本的に同じ方法で実行しているため、意味がありません。
//this code runs when user clicks a player's status icon
public void playerStatusIconClicked(View v)
{
//loop through buttons to determine which player's button was clicked
for (int i = 0; i < playerList.size(); i++)
{
if (v.getId() == playerStatusIVList.get(i).getId())
{
calledPlayer = i; //instance variable
loadStatusIconGUI();
}//if
}//for
}//method playerStatusIconClicked
//showStatusIconGUI inflates the "select status icon" GUI
//and handles the user selecting an icon
private void loadStatusIconGUI()
{
//inflate the GUI for the showStatusIcon dialog (inflater is an instance variable)
View view = inflater.inflate(R.layout.dialog_select_icon, null);
//if the list has something in it, start from fresh
if (!selectStatusIVList.isEmpty())
{
selectStatusIVList.clear();
}
//list of icons in the "select status icon" dialog
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV0));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV1));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV2));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV3));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV4));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV5));
selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV6));
//create a dialog so user can select an icon
AlertDialog.Builder selectIconDialog = new AlertDialog.Builder(this);
selectIconDialog.setView(view); //set the Dialog's custom view
selectIconDialog.setTitle(R.string.title_select_icon);
selectIconDialog.setNegativeButton(R.string.close, null);
selectIconDialog.show();
}//showStatusIconGUI
//Handle clicks in the "select status icon" dialog
//Assigns a new status to the player
public void statusIconClicked(View v)
{
Toast message;
for (int i = 0; i < selectStatusIVList.size(); i++)
{
if (v.getId() == selectStatusIVList.get(i).getId())
{
message = Toast.makeText(
MafiaTracker.this, "new status: " statusID[i], Toast.LENGTH_SHORT);
message.show();
playerList.get(calledPlayer).setImage(imageID[i]);
playerList.get(calledPlayer).setStatus(statusID[i]);
}
}
updateViewPlayerGUI();
}
imageID[i]とstatusID[i]は、各ステータス文字列とステータスイメージのIDを含むint配列を参照していることに注意してください。
xmlファイルを投稿することはできますが、124行の長さなので、投稿したくありません。xmlファイルの各ImageViewにはIDがあることを知っているだけなので、「if(!selectStatusIVList.isEmpty())」の部分から始めて、これらのNullPointerExceptionsが発生する理由を理解できません。後の他の呼び出し。
助けてください!