ruilin10086
RLin2013
采纳率100%
2015-01-08 03:38 阅读 3.8k

为什么用handler接收不到list对象

这是错误提示:

at android.os.Handler.handleCallback(Handler.java:615)

at android.os.Handler.dispatchMessage(Handler.java:92)

at android.os.Looper.loop(Looper.java:153)

at android.app.ActivityThread.main(ActivityTh

这是代码:

```private Handler listHandler = new Handler() {
public void handleMessage(Message msg) {

        List<Map<String, String>> result =  (List<Map<String, String>>) msg.obj;

        switch (msg.what) {
        case AutoListView.REFRESH:
            lv_wanzheng.onRefreshComplete();
            //listCount.clear();
            listCount.addAll(result);
            break;
        case AutoListView.LOAD:
            lv_wanzheng.onLoadComplete();
            listCount.addAll(result);
            break;
        }
        lv_wanzheng.setResultSize(result.size());
        wanzhengAdapter.notifyDataSetChanged();
    };

};

new Thread(new Runnable() {

        @Override
        public void run() {

            Message msg = new Message();
            msg.what = whatNum;
            msg.obj = getData();
            listHandler.sendMessage(msg);
        }
    }).start();

    private List<Map<String, String>> getData() {
    JsonMessage jm = new JsonMessage();
    String[] title = jm.getTitle();
    String[] time = jm.getTime();
    String[] image1 = jm.getimage1();
    String[] image2 = jm.getimage2();
    String[] url = jm.getUrl();

    List<Map<String, String>> listdata = new ArrayList<Map<String, String>>();
    for (int i = 0; i < image1.length; i++) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("title", title[i]);
        map.put("time", time[i]);
        map.put("image1", image1[i]);
        map.put("image2", image2[i]);
        map.put("url", url[i]);
        listdata.add(map);
    }
    return listdata;
}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    bdmh bdmh 2015-01-08 03:48

    不能直接传递对象,要序列化,msg.obj = (Parcelable) object
    接收时,MyObject objectRcvd = (MyObject) msg.getData().getParcelable("MyObject");

    点赞 评论 复制链接分享

相关推荐