java.lang.RuntimeException: Only one Looper may be created per thread解决方法

简介: java.lang.RuntimeException: Only one Looper may be created per thread解决方法

题外话

各位友友们,每次出异常之后不要直接问同事直接去百度,要养成一个良好的习惯,先去自己分析,出这个异常的原因是什么,对照着代码,看打印的日志也好debug一步一步走也好,找到出异常的代码块,分析为什么会出异常,然后自己再进行调试,只有自己动脑思考了,才会成长才能有所收获。

------------------------

首先查看报错信息

Only one Looper may be created per thread:每个线程只能创建一个Looper

TTToast.java:10:错误发生在TTToast.java的第10行,咱们点过去查看

方法解释:

Looper.prepare():为当前线程提供一个Looper的实例

TToast.show(context, msg):展示消息

Looper.loop():在线程中执行消息队列,让 Looper 开始工作,从消息队列里取消息,处理消息

分析

每个线程只能创建一个Looper,说明其他地方已经调用了show这个方法,在线程中已经创建了Looper,不能再执行Looper.prepare()这个方法了

解决方法

判断当前线程是否创建了Looper,如果未创建则执行Looper.prepare()

如果已创建,直接执行后续操作即可

(~~~~~~~~~~~~~~~~~~~~~~~~~~~~)

目录
相关文章
|
2月前
|
Java 编译器
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
34 0
|
5月前
|
Java
【Java报错】多数据源mapper异常more than one `primary` bean found among candidates: [sqlSessionFactory] 问题分析解决
【Java报错】多数据源mapper异常more than one `primary` bean found among candidates: [sqlSessionFactory] 问题分析解决
138 0
|
7月前
|
Java 编译器
this version of the Java Runtime only recognizes class file versions up to 52.0
this version of the Java Runtime only recognizes class file versions up to 52.0
95 0
|
Oracle Java 关系型数据库
JDK/JAVA Exception NSWindow drag regions should only be invalidated on the Main Thread
JDK/JAVA Exception NSWindow drag regions should only be invalidated on the Main Thread
123 0
|
Java
this version of the Java Runtime only recognizes class file versions up to 52.0
this version of the Java Runtime only recognizes class file versions up to 52.0
189 0
java.io.IOException: Requested internal only, but not enough space
java.io.IOException: Requested internal only, but not enough space
406 0
|
Java 编译器
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
1202 0
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
java中出现Syntax error, annotations are only available if source level is 1.5 or greater
java中出现Syntax error, annotations are only available if source level is 1.5 or greater
java中出现Syntax error, annotations are only available if source level is 1.5 or greater
|
消息中间件 NoSQL Java
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
151 0
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
|
Java Apache
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environ
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environ
290 0
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environ