所以我在 onPostExecute 方法期间填充 listActivity 时遇到问题。SingleData的结果列表是正确的...然后我使用自定义适配器绑定到android.R.id.list...
但它给了我错误......我真的不明白为什么......所以这是适配器的代码......:
private class RequestAdapter extends ArrayAdapter<SingleData> {
private int _resource;
private LayoutInflater _inflater;
private Context _context;
public RequestAdapter(Context context, int textViewResourceId,
List<SingleData> objects) {
super(context, textViewResourceId, objects);
_resource = textViewResourceId;
_context = context;
_inflater = LayoutInflater.from(_context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = (ListView)_inflater.inflate(_resource,null);
SingleData sdd = getItem(position);
ImageView iv = (ImageView)convertView.findViewById(R.id.imagePlaceHolder_IV);
iv.setImageBitmap(sdd.thumbIMG);
TextView tv = (TextView)convertView.findViewById(R.id.createdAt_TV);
tv.setText(sdd.timeStamp);
// TODO Auto-generated method stub
return convertView;
}
}
这是 onPostExecute:
private class DownloadTheImages extends AsyncTask<Void, Void, List<SingleData>> {
private Context _ctx;
public DownloadTheImages(Context ctx) {
_ctx = ctx;
}
protected void onPostExecute(List<SingleData> result) {
ListView mainLV = (ListView)findViewById(android.R.id.list);
mainLV.setAdapter(new RequestAdapter(_ctx, R.layout.single_row, result));
}
protected List<SingleData> doInBackground(Void... params) {
.....
....
}
}
和 LOGCAT:
10-20 15:02:55.166: E/AndroidRuntime(761): FATAL EXCEPTION: main
10-20 15:02:55.166: E/AndroidRuntime(761): java.lang.NullPointerException
10-20 15:02:55.166: E/AndroidRuntime(761): at com.mimiedesign.dingle.PictureStreamViewer$DownloadTheImages.onPostExecute(PictureStreamViewer.java:103)
10-20 15:02:55.166: E/AndroidRuntime(761): at com.mimiedesign.dingle.PictureStreamViewer$DownloadTheImages.onPostExecute(PictureStreamViewer.java:1)
10-20 15:02:55.166: E/AndroidRuntime(761): at android.os.AsyncTask.finish(AsyncTask.java:417)
10-20 15:02:55.166: E/AndroidRuntime(761): at android.os.AsyncTask.access$300(AsyncTask.java:127)
10-20 15:02:55.166: E/AndroidRuntime(761): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
任何线索?...谢谢..
这些是较新的错误:
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.makeAndAddView(ListView.java:1745)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.fillDown(ListView.java:670)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.fillFromTop(ListView.java:727)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.layoutChildren(ListView.java:1598)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)