下面是微调器中onItemSelected调用的代码。有时,即使关闭应用程序,我也会得到空指针异常。错误的图片附在这篇文章中。
/**
* Store the selected product
* @param parent
* @param view
* @param position
* @param id
*/
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
QuickListItem selectedSpinnerProduct = productAdapter.getItem(position);
if (selectedSpinnerProduct != null) {
mgrApp.storeSharedPrefLong(ConstantsQuickList.SHARED_PREF_PRODUCT_ID,
selectedSpinnerProduct.getId());
}
SpannableStringBuilder builder = getPendingCallCount(products,
selectedSpinnerProduct);
((TextView) view).setText(builder, TextView.BufferType.SPANNABLE);
//Hide the performance tracker as product will change
ViewProspects.crdvPerformanceTracker.setVisibility(View.GONE);
populateSalesTracker(typeOfOperation,ConstantsProspects.INVALID_STRING);
}
如果selectedSpinnerProduct为空,则会出现问题。因此,请检查所有使用了[[selectedSpinnerProduct的地方是否为null。
if (selectedSpinnerProduct != null) {
mgrApp.storeSharedPrefLong(ConstantsQuickList.SHARED_PREF_PRODUCT_ID,
selectedSpinnerProduct.getId());
SpannableStringBuilder builder = getPendingCallCount(products,
selectedSpinnerProduct);
((TextView) view).setText(builder, TextView.BufferType.SPANNABLE);
}