我用一个Thread去访问远程数据库,在过程中会弹出dialog,请求结束时,在handler里面关闭dialog
多次请求,就会出现闪退。报错如下
02-06 11:23:41.609: W/dalvikvm(22208): threadid=1: thread exiting with uncaught exception (group=0x40c99450)
02-06 11:23:41.609: E/AndroidRuntime(22208): FATAL EXCEPTION: main
02-06 11:23:41.609: E/AndroidRuntime(22208): java.lang.NullPointerException
02-06 11:23:41.609: E/AndroidRuntime(22208): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2993)
02-06 11:23:41.609: E/AndroidRuntime(22208): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 11:23:41.609: E/AndroidRuntime(22208): at android.os.Looper.loop(Looper.java:137)
02-06 11:23:41.609: E/AndroidRuntime(22208): at android.app.ActivityThread.main(ActivityThread.java:4794)
02-06 11:23:41.609: E/AndroidRuntime(22208): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 11:23:41.609: E/AndroidRuntime(22208): at java.lang.reflect.Method.invoke(Method.java:511)
02-06 11:23:41.609: E/AndroidRuntime(22208): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-06 11:23:41.609: E/AndroidRuntime(22208): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-06 11:23:41.609: E/AndroidRuntime(22208): at dalvik.system.NativeStart.main(Native Method)
这是源码
valuemap.clear();
valuemap.put("action", "/android/receiveLandMaterial.shtml");//线体验证的地址
valuemap.put("lineNo", lineNoValue);
valuemap.put("drawingNo", drawingNoValue);
valuemap.put("materialBarcode", ch.subSequence(0, ch.length()-1));
if(testdialog==null){
testdialog = new ShowDialog().showTestDialog(context, "正在领料当中");
}else{
testdialog.show();
}
editmap.put("szsdialog", testdialog);
editmap.put("szscheckmark", "1");
thread = new Thread(new CommonRun(editmap,valuemap)); //启动线程开始校验4
thread.start();
Message msg = new Message();
Map<String,Object> resultMap = new CheckTextDAO().checktext(valuemap,editmap);
Bundle b = new Bundle();
for(String key : resultMap.keySet()){
b.putString(key, resultMap.get(key).toString());
}
//b.putString("message", (String) resultMap.get("message"));
msg.setData(b);
resetHandler.sendMessage(msg);
Context context = (Context) editmap.get("thisActivity");
/**
* 如果有提示框,让提示框消失
*/
if(editmap.get("szsdialog")!=null){
AlertDialog testdialog = (AlertDialog) editmap.get("szsdialog");
if(testdialog!=null&&testdialog.isShowing()){
testdialog.setCancelable(true);
testdialog.dismiss();
}
editmap.remove("szsdialog");
}
//接下来给出提示信息
TextView tishi = (TextView) editmap.get("tishi");
if(tishi!=null){
tishi.setTextColor(android.graphics.Color.RED);
tishi.setText(bundle.getString("message"));
}
//Toast.makeText(context, bundle.getString("message"), 2000).show();
/**
* 出错了发出声音提示
*/
SoundPlayUtils sound = new SoundPlayUtils();
if(context!=null){
sound.init(context);
sound.play(1);
/**
* 如果出错了,给出震动提示
*/
new VibrateHelp().vSimple(context, 500);
}
//对字段进行操作
if(StringX.isEmpty(bundle.getString("check"))){
//获取那个字段检验失败
EditText thisedite = (EditText) editmap.get(bundle.get("check"));
if(thisedite!=null){
//清空当前字段
thisedite.setText("");
thisedite.requestFocus();//焦点的变化
}
}