Android-Bug收集
阿新 • • 發佈:2019-01-02
- java.lang.IllegalStateException: RecyclerView has no LayoutManager
at android.support.v7.widget.RecyclerView.generateLayoutParams(RecyclerView.java:3256)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
解決方式:給RecycleView設定LayoutManger,recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
如果有對RecycleView新增HeaderView,該設定請放到新增載入Header佈局之前
2.
FATAL EXCEPTION: main
Process: com.fotoable.torchflashlight, PID: 5764
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.coolspan.torchflashlight-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.coolspan.torchflashlight-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.fotoable.torchflashlight-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.coolspan.torchflashlight-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4778)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)?
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)?
at android.app.ActivityThread.access$1500(ActivityThread.java:135)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:136)?
at android.app.ActivityThread.main(ActivityThread.java:5017)?
at java.lang.reflect.Method.invokeNative(Native Method)?
at java.lang.reflect.Method.invoke(Method.java:515)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)?
at dalvik.system.NativeStart.main(Native Method)?
解決方法:可能是新增MultiDex分包,但未初始化的原因,在Application中初始化即可。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
3.
此問題是使用系統DownloadManager導致的
因為我設定了下載通知不可見;
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
java.lang.SecurityException: Invalid value for visibility: 2
at android.os.Parcel.readException(Parcel.java:1546)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1260)
at android.app.DownloadManager.enqueue(DownloadManager.java:1336)
解決方法:
新增許可權即可
<!--DownloadManager下載時不顯示Notification-->
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
4.
問題:使用 Collections.sort導致出現的異常
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:743)
at java.util.TimSort.mergeAt(TimSort.java:479)
at java.util.TimSort.mergeCollapse(TimSort.java:406)
at java.util.TimSort.sort(TimSort.java:210)
at java.util.TimSort.sort(TimSort.java:169)
at java.util.Arrays.sort(Arrays.java:2010)
at java.util.Collections.sort(Collections.java:1883)
程式碼:
Collections.sort(appInfoList, new Comparator<AppInfo>() {
@Override
public int compare(AppInfo o1, AppInfo o2) {
int value = (int) (o1.getLastUpdateTime() - o2.getLastUpdateTime());
int state = 0;
if (value > 0) {
state = 1;
} else if (value < 0) {
state = -1;
}
Log.e("AppList", "value:::::" + state);
return state;
}
});
解決方法:
網上說設定:
System.setProperty(“java.util.Arrays.useLegacyMergeSort”, “true”);
好像不好使啊。
解決後的程式碼是,型別轉換導致:
long value = (o1.getLastUpdateTime() - o2.getLastUpdateTime());
5.
異常:使用了PagerAdapter出現的問題
FATAL EXCEPTION: main
Process: com.xxx.youtube.music, PID: 22803
java.lang.UnsupportedOperationException: Required method instantiateItem was not overridden
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:178)
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:111)
出錯程式碼:
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = View.inflate(context, R.layout.view_home_banner_item, null);
ImageView coverIv = (ImageView) itemView.findViewById(R.id.cover_iv);
int rid = bannerList.get(position % bannerList.size());
coverIv.setImageResource(rid);
container.addView(itemView);
return super.instantiateItem(container, position);
}
解決方法:
return super.instantiateItem(container, position);
改為:
return itemView;
不認真導致的錯誤