ユーザーが 2 番目のアクティビティを開始できるアクティビティがあります。2 番目のアクティビティには、配列リストに追加するアイテムのリストがあります。前のアクティビティに戻ったら、配列リストのサイズを表示したいと思います。
ただし、onResume() に問題があります。最初のアクティビティが作成されたときに呼び出され、最初に起動したときに配列リストが存在しないため、結果としてエラーが発生します!
onResume():
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
getIntentData();
calcSubTotal(orderData);
}
getIntentData():
public void getIntentData(){
b = new Bundle();
b = getIntent().getExtras();
orderData = b.getParcelable("order");
Toast.makeText(this.getApplicationContext(), orderData.size(), Toast.LENGTH_LONG).show();
}
2 番目のアクティビティの onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starters);
createTestData();
b = new Bundle();
orderData = new MenuItemList();
adapter = new MenuItemArrayAdapter(this, starters);
this.setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(this.getApplicationContext(), l.getItemAtPosition(position).toString() + " clicked", Toast.LENGTH_LONG).show();
//add clicked item to orderData....
MenuItem m = (MenuItem)l.getItemAtPosition(position);
//create new item
orderData.add(m);
}
どうすればこれを制御できるのでしょうか?
エラー:
java.lang.RuntimeException: アクティビティを再開できません {com.example.waitronproto3/com.example.waitronproto3.SectionsActivity}: java.lang.NullPointerException