当前位置: 代码迷 >> 综合 >> Android出现java.lang.RuntimeException: Can‘t toast on a thread that has not called Looper.prepare()
  详细解决方案

Android出现java.lang.RuntimeException: Can‘t toast on a thread that has not called Looper.prepare()

热度:39   发布时间:2023-10-18 17:48:53.0

今天又是写代码的美好一天>_<
往常运行的好好的程序,今天运行在弹出吐司(Toast)时却出现了java.lang.RuntimeException: Can’t toast on a thread that has not called Looper.prepare(),ε=(?ο`*)))唉

Android出现java.lang.RuntimeException: Can‘t toast on a thread that has not called Looper.prepare()
   Process: com.qdsg.screen, PID: 23288
    java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare()
,程序在主线程中创建handler后会创建一个looper对象,而子线程却不会,所以我在我使用Toast前先执行Looper.prepare();使用Toast后执行 Looper.loop();

if (TextUtils.isEmpty( serverPort )) {Looper.prepare();getView().showToast( R.string.ServerPort_not_null );Looper.loop();getView().dismissLoginDialog();return;
}
  相关解决方案