我試圖採取從ViewHolder去年穀歌IO羅曼蓋伊的建議的列表,以優化列表視圖從例如: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ (感謝管理員) 但每當我試着翻轉列表或甚至使其移動一點,應用程序崩潰,發生了什麼事?任何幫助,將不勝感激:) 這裏是我做過什麼>試圖優化ListView和失敗
private class OrderAdapter extends ArrayAdapter<Order> {
private ArrayList<Order> items;
LayoutInflater mInflater;
public OrderAdapter(Context context, int textViewResourceId, ArrayList<Order> items) {
super(context, textViewResourceId, items);
mInflater = LayoutInflater.from(context);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, parent, false);
holder = new ViewHolder();
holder.tt = (TextView) convertView.findViewById(R.id.toptext);
holder.bt = (TextView) convertView.findViewById(R.id.bottomtext);
} else {
holder = (ViewHolder) convertView.getTag();
}
Order o = items.get(position);
if (o != null) {
if (holder.tt != null) {
holder.tt.setText("Name: " + o.getOrderName());
}
if (holder.bt != null) {
holder.bt.setText("Status: " + o.getOrderStatus());
}
}
return convertView;
}
}
這是錯誤消息我得到了,對不起,我不知道如何格式化>
致命異常:主要 的java .lang.NullPointerException at com.softberries.lve.SoftwarePassionView $ OrderAdapter.getView(SoftwarePassionView.java:98) at android.widget.AbsListView.obtainView(AbsListView.java:1294) at android.widget.ListView.makeAndAddView( ListView.java:1727) at android.widget.ListView.fillDown(ListView.java:652) 在android.widget.ListView.fillGap(ListView.java:623) 在android.widget.AbsListView.trackMotionScroll(AbsListView.java:2944) 在android.widget.AbsListView.onTouchEvent(AbsListView.java:2065) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897) 在android上的android.view.View.dispatchTouchEvent(View.java:3766) android.widget.ListView.onTouchEvent(ListView.java:3315) view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) at android.view。 ViewGroup.dispatchTouchEvent(ViewGroup.java:936) at com.android.inter nal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1671) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) at android.app.Activity.dispatchTouchEvent( Activity.java:2086) at android.view.View.Root.handleMessage(ViewRoot.java:1785) at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1655) 。 os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang。方法.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) a t com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main (Native Method)
在什麼消息出現在logcat的 – Ayudh 2011-04-06 07:42:51
ERROR/AndroidRuntime(381)崩潰的時間:java.lang中。NullPointerException – user685275 2011-04-06 08:14:10