android 异常处理:android.view.viewroot$calledfromwrongthreadexception
来源:互联网 发布:淘宝宝贝描述图片制作 编辑:程序博客网 时间:2024/06/05 14:13
在写线程时
mListView.setAdapter(adapter);
}
}
};
子线程中是不能做任何数据更新的 。
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what ==20){
@Override
public void handleMessage(Message msg) {
if(msg.what ==20){
//界面在handle中更新即可解决该异常
adapter = new ProductsAdapter(getActivity(), list2);
adapter = new ProductsAdapter(getActivity(), list2);
mListView.setAdapter(adapter);
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
Gson gson = new Gson();
Type listType = new TypeToken<List<ProductList>>() {
}.getType();
String json = NerService.getServerJsonWithType(NerService.PRODUCTS_URL);
System.out.println("json:" + json);
List<ProductList> mProductList = gson.fromJson(json, listType);
list2 = new ArrayList<HashMap<String, Object>>();
for (ProductList list : mProductList) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", list.getId());
map.put("name", list.getName());
System.out.println("name===>"+list.getName());
map.put("jiliangguige", list.getJiliangguige());
map.put("baozhuangguige", list.getBaozhuangguige());
map.put("jixing", list.getJixing());
map.put("baozhuang", list.getBaozhuang());
map.put("guige", list.getGuige());
map.put("pizhunwenhao", list.getPizhunwenhao());
map.put("yibaoleixing", list.getYibaoleixing());
map.put("OTC", list.getOTC());
map.put("chufangleixing", list.getChufangleixing());
map.put("pics", list.getPics());
map.put("manufacturer", list.getManufacturer());
map.put("m_price", list.getM_price());
map.put("category_1", list.getCategory_1());
map.put("category_2", list.getCategory_2());
list2.add(map);
}
Message message = Message.obtain();
message.what =20;
handler.sendMessage(message);
}
}).start();
@Override
public void run() {
Gson gson = new Gson();
Type listType = new TypeToken<List<ProductList>>() {
}.getType();
String json = NerService.getServerJsonWithType(NerService.PRODUCTS_URL);
System.out.println("json:" + json);
List<ProductList> mProductList = gson.fromJson(json, listType);
list2 = new ArrayList<HashMap<String, Object>>();
for (ProductList list : mProductList) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", list.getId());
map.put("name", list.getName());
System.out.println("name===>"+list.getName());
map.put("jiliangguige", list.getJiliangguige());
map.put("baozhuangguige", list.getBaozhuangguige());
map.put("jixing", list.getJixing());
map.put("baozhuang", list.getBaozhuang());
map.put("guige", list.getGuige());
map.put("pizhunwenhao", list.getPizhunwenhao());
map.put("yibaoleixing", list.getYibaoleixing());
map.put("OTC", list.getOTC());
map.put("chufangleixing", list.getChufangleixing());
map.put("pics", list.getPics());
map.put("manufacturer", list.getManufacturer());
map.put("m_price", list.getM_price());
map.put("category_1", list.getCategory_1());
map.put("category_2", list.getCategory_2());
list2.add(map);
}
Message message = Message.obtain();
message.what =20;
handler.sendMessage(message);
}
}).start();
0 0
- android 异常处理:android.view.viewroot$calledfromwrongthreadexception
- Android--android.view.ViewRoot$CalledFromWrongThreadException异常解决
- android.view.ViewRoot$CalledFromWrongThreadException
- android.view.ViewRoot$CalledFromWrongThreadException
- 报异常:android.view.ViewRoot$CalledFromWrongThreadException
- 关于android.view.ViewRoot$CalledFromWrongThreadException 异常
- android.view.ViewRoot$CalledFromWrongThreadException 异常的解决方案
- android.view.ViewRoot$CalledFromWrongThreadException 异常的解决
- 发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案
- 发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案
- 发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案
- android.view.ViewRootImpl$CalledFromWrongThreadException异常处理
- Android编程中,发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案
- Android编程中,发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方案
- 子线程更新UI会发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方法
- 子线程更新UI会发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方法
- 子线程更新UI会发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方法 .
- 子线程更新UI会发生android.view.ViewRoot$CalledFromWrongThreadException异常的解决方法
- MAC OS X下nuXmv对libxml2版本的要求
- Emmet安装到到 Sublime text 3
- Android4.3引入的UiAutomation新框架官方简介
- CATransform3D 特效详解
- jquery UI学习笔记-知问前段之邮箱自动补全
- android 异常处理:android.view.viewroot$calledfromwrongthreadexception
- IBM Ponder This问题
- NSJSONSerialization-JSON数据与NSDictionary和NSArray之间的转化
- 字符串比较查询
- 教你把pdf怎么转换成ppt
- Spring MVC 学习笔记3 - 利用Default Annotation 模式获取请求,使Controller与View对应,并传值。
- C# WinForm窗体及其控件自适应各种屏幕分辨率
- iOS int和NSInteger的区别
- ubuntu创建新用户并增加管理员权限