Wrong state class, expecting View State but received class XXXXX instead.

这里记录下遇到的bug

Java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class XXXXX instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/XXXXX. Make sure other views do not use the same id.

看log日志是说view的id相同了,查了半天也没有发现哪里有问题,确定XML里的id没有重复的。

出现这种bug,要查看下是否有以下情况:

1.这个bug发生在activityB返回到actiivtyA,并设置了setResult()并有数据返回时,如果是请查看A的onActivityResult()里是否对返回值data 做了判空处理 if(data==null)  ,如果没有data==nul,然后你再去取数据,就会crash,然后上面那个bug出现了。

2.这种情况没有测试过,另外查看是否有对activity设置 Android:launchMode="singleInstance"。二个activuty没有在同一个栈里,也会导致setResult()失败。

你可能感兴趣的:(Wrong state class, expecting View State but received class XXXXX instead.)