ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
ThreadException线程异常,只能在原始线程(主线程 )更新视图
|
在使用Retrofit+RxJava的时候,没有使用observerOn(AndroidSchedulers.mainThread()),则未返回主线程,不能更新UI
代码如下:
HttpClient.getInstance().service.travel(new ReqTravel("userId"))
.subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
.subscribe(travel -> {
if (travel != null) {
if (travel.result.equals(NetWorkState.SUCCEES)) {
}
}
}, throwable -> {
.subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
.subscribe(travel -> {
if (travel != null) {
if (travel.result.equals(NetWorkState.SUCCEES)) {
}
}
}, throwable -> {
解决方法:RxJava的时候,Schedulers.io()和AndroidSchedulers.mainThread()一起使用
StackOverflowError 当前线程的栈满了 ,也就是函数调用层级过多导致。 |
SecurityException Android6.0未授予权限 |
与网络有关的异常四个:
1、NetworkOnMainThreadException
2、ConnectException
3、SockerTimeoutException
4、UnkowHostException
|
开发中最常见的几个异常
1、ArrayIndexOutOfBoundsException数据越界
2、NullPointerException空指针
3、IllegalStateException
4、ActivityNotFoundException
5、StringIndexOutOfBoundsException:字符串越界
比如 String s="hello"; char c=s.chatAt(6);
6、IllegalArgumentException:非法参数
|
1、NumberFormatException:继承IllegalArgumentException,字符串转换为数字时。
比如int i= Integer.parseInt("ab3");
2、ClassCastException:类型转换错误
比如 Object obj=new Object(); String s=(String)obj;
|