Android 处理程序循环
谁能告诉我这个 logcat 有什么问题吗
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): FATAL EXCEPTION: Speedometer
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.os.Handler.<init>(Handler.java:121)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.widget.Toast.<init>(Toast.java:68)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.widget.Toast.makeText(Toast.java:231)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI.updateGUI(WhereAmI.java:883)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI.access$5(WhereAmI.java:860)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI$4.run(WhereAmI.java:845)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at java.util.Timer$TimerImpl.run(Timer.java:284)
can any one please tell me what is the problem with this logcat please
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): FATAL EXCEPTION: Speedometer
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.os.Handler.<init>(Handler.java:121)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.widget.Toast.<init>(Toast.java:68)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at android.widget.Toast.makeText(Toast.java:231)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI.updateGUI(WhereAmI.java:883)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI.access$5(WhereAmI.java:860)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at com.paad.whereami.WhereAmI$4.run(WhereAmI.java:845)
06-23 11:09:12.060: ERROR/AndroidRuntime(1116): at java.util.Timer$TimerImpl.run(Timer.java:284)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试在您创建的新线程中启动 Android 事件处理程序,例如 onLocationChanged。在线程类的“run()”方法中,需要调用Looper.prepare(),注册事件处理程序,然后调用Looper.loop()。当线程完成后,调用 Looper.myLooper().quit() 方法退出。
例子:
You're trying to start an Android event handler such as onLocationChanged inside a new thread that you created. In the "run()" method of the thread class, you need to call Looper.prepare(), register the event handler, then call Looper.loop(). When you're done with the thread, call the Looper.myLooper().quit() method to exit.
Example:
Yoi 需要从 ui 线程显示 toast。您可以使用 Activity 上的 runOnUiThread 方法来完成此操作。
以下是示例的解释 Android:线程中的 Toast
Yoi will need to show toast from ui thread. You can do it using runOnUiThread method on Activity.
Here is an explanation with example Android: Toast in a thread