我的应用程序将一个整数值添加到一个向量,然后想知道该向量的大小。
if(nearSelected||middleSelected||farSelected){
ArrayList<Integer> distance = new ArrayList<Integer>();
//Which distance(s) has the user selected?
if(nearSelected){distance.add(1);}
if(middleSelected){distance.add(2);}
if(farSelected){distance.add(3);}
//Attempt to display the number of choices picked to the user
try {
Toast.makeText(getBaseContext(), distance.size(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.i(LOG_TAG, e.toString());
}
}
不幸的是,尝试获取distance.size()
会导致NotFoundException
. 代码的所有其他部分运行良好,只是这部分崩溃了。我哪里搞砸了?