butterknife zelezny threw an uncaught ArrayIndexOutOfBoundsException
Butterknife突然就爆出了这个问题,刚开始以为是注解工具出了问题,就使用了findviewbyid,后来一个个打的时候才发现是我的id写错了,如果你也是这样就检查一下你的id是不是下划线为第一个
Error:Could not find method compile() for arguments [com.android.support:cardview-v7:25.3.1] on DefaultExternalModuleDependency{group='com.android.support', name='appcompat-v7', version='25.3.1', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
解决办法:用着用着就这样了,刚开始真不知道为什么,后来看到build.gradl里面,compile里面的都叠成一行了,好吧,他说找不到"not find method compile() for arguments" 原来是这个原因,将其加上换行就好了,
mob分享,本来上线的时候是没问题的,后来莫名其妙魅族手机分享失败,小米手机确实成功的,这个就让人很坑爹,小米手机没事.魅族手机有问题.这就让我一直找魅族手机的原因,后来网上说图片的原因.我就改了规格,也叫后台改了图片,但是还是无济于事.一直分享失败,最后oks.setCallback才知道,一直显示NullPointerException Reader
分割线-------------------------------------------------------------------------------
Process: com.cdzb.milier, PID: 10368
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 15(offset:15).state:30
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5504)
at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:282)
at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:336)
at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:349)
at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:356)
at android.support.v7.widget.GapWorker.run(GapWorker.java:387)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6360)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
使用recycleview的时候都会出现这个问题,本身就是一个频繁刷新的一个控件,这个是他本身内部的bug,RecyclerView是Android-support-v7-21版本中新增的一个Widget,RecyclerView在刷新数据的时候会出现异常,看报错就知道,并没有报应用层的bug,
有2个解决办法:
- 捕获了异常,防止crash掉,这个是谷歌recycleview导致的,所以这样做能解决这个问题,在创建recycleview的
LinearLayoutManager的时候替换成LinearLayoutManagerWrapper,
public class LinearLayoutManagerWrapper extends LinearLayoutManager {
public LinearLayoutManagerWrapper(Context context) {
super(context);
}
public LinearLayoutManagerWrapper(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public LinearLayoutManagerWrapper(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
System.out.print("recycle的异常捕获了");
}
}
}
2.如果这样还是不能解决问题,在每次改动adapter的数据的时候就用Adapter.notifyDataSetChanged();