Android crash解决集锦
外接U盘长点击一文件夹选中后拨出OTG线提示停止运行
log内容:
----- timezone:GMT
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: FATAL EXCEPTION: main
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: Process: com.android.documentsui, PID: 5655
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: java.lang.RuntimeException: Unable to destroy activity {com.android.documentsui/com.android.documentsui.FilesActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4298)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4316)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread.-wrap6(ActivityThread.java)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1588)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:110)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.os.Looper.loop(Looper.java:203)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6251)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:63)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.BulkCursorToCursorAdaptor.getCount(BulkCursorToCursorAdaptor.java:69)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:197)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.RootCursorWrapper.onMove(RootCursorWrapper.java:79)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:236)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.FilteringCursorWrapper.onMove(FilteringCursorWrapper.java:152)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:236)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.Model.getItem(Model.java:450)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.DirectoryFragment$SelectionModeListener.onItemStateChanged(DirectoryFragment.java:519)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.MultiSelectManager.notifyItemStateChanged(MultiSelectManager.java:532)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.MultiSelectManager.clearSelectionQuietly(MultiSelectManager.java:287)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.MultiSelectManager.clearSelection(MultiSelectManager.java:262)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at com.android.documentsui.dirlist.DirectoryFragment.onDestroyView(DirectoryFragment.java:218)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.Fragment.performDestroyView(Fragment.java:2570)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1153)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:2067)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.FragmentController.dispatchDestroy(FragmentController.java:242)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.Activity.performDestroy(Activity.java:6867)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4285)
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: ... 9 more
分析解决:
11-22 10:19:48.753412 5655 5655 E AndroidRuntime: java.lang.RuntimeException: Unable to destroyactivity {com.android.documentsui/com.android.documentsui.FilesActivity}:android.database.StaleDataException: Attempted to access a cursor after it hasbeen closed.
crash原因是不能销毁活动,引起的原因是旧数据异常:试图访问一个已经关闭的游标。
根据报错log:at com.android.documentsui.dirlist.DirectoryFragment$SelectionModeListener.onItemStateChanged(DirectoryFragment.java:519)
public void onItemStateChanged(StringmodelId,boolean selected){
finalCursor cursor=mModel.getItem(modeId);
StringmimeType=null;
if(cursor==null){
……
}
}
应该是这里的cursor在拔掉OTG线的时候关闭了,而选中操作的监听事件还在试图引用cursor,这也直接导致了atcom.android.documentsui.dirlist.DirectoryFragment.onDestroyView(DirectoryFragment.java:218)这个方法报错,即无法销毁活动。
解决方法是设置一个布尔标志位isDestroyView,默认为false,当拔出OTG线也就是视图要销毁的时候,设为true,在onItemStateChanged方法中增加判断语句,如下
public void onItemStateChanged(StringmodelId,boolean selected){
if(isDestroyView){
return;
}
finalCursor cursor=mModel.getItem(modeId);
StringmimeType=null;
if(cursor==null){
……
}
}
当视图销毁后就不进行事件的监听操作了。
不要忘记在onCreateView中对标志位进行恢复操作,置为false。
问题描述:横屏显示导致导航栏报错
log内容:
01-01 16:58:27.265 D/AndroidRuntime( 9998): Shutting down VM
01-01 16:58:27.266 E/AndroidRuntime( 9998): FATAL EXCEPTION: main
01-01 16:58:27.266 E/AndroidRuntime( 9998): Process: com.android.systemui, PID: 9998
01-01 16:58:27.266 E/AndroidRuntime( 9998): android.view.WindowManager$BadTokenException: Unable to add window [email protected] -- another window of type 2019 already exists
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.systemui.statusbar.phone.NavigationBarFragment.create(NavigationBarFragment.java:726)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.systemui.statusbar.phone.StatusBar.createNavigationBar(StatusBar.java:1225)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.systemui.statusbar.phone.StatusBar.showNavigationBar(StatusBar.java:1239)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:506)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.os.Handler.dispatchMessage(Handler.java:105)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.os.Looper.loop(Looper.java:164)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at android.app.ActivityThread.main(ActivityThread.java:6565)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at java.lang.reflect.Method.invoke(Native Method)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
01-01 16:58:27.266 E/AndroidRuntime( 9998): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
分析原因:已经存在一个type类型为2019的view,这里应该是创建view导致的,创建的方法是NavigationBarFragment.create,调用该方法进行创建的位置是createNavigationBar,生成的对象是mNavigationBarView,导致问题的原因应该就是它重复创建了,showNavigationBar调用createNavigationBar,最终是在showNavigationBar中实现创建,这里添加判断条件,当还存在相应的view时,不进行view创建。如下
if(showNav && mNavigationBarView ==null && mNavigationBar ==null){
createNavigationBar();
}
问题描述:
从文件管理器中使用音乐应用播放音乐报错
log内容:
FATAL EXCEPTION: main
01-01 13:22:35.082 E/AndroidRuntime( 9524): Process: com.android.music, PID: 9524
01-01 13:22:35.082 E/AndroidRuntime( 9524): java.lang.RuntimeException: Failure delivering result ResultInfo{[email protected]:requestPermissions:, request=100, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.android.music/com.codeaurora.music.custom.PermissionActivity}: java.lang.SecurityException: UID 10095 does not have permission to content://com.android.providers.media.documents/document/audio%3A299 [user 0]; you could obtain access using ACTION_OPEN_DOCUMENT or related APIs
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread.deliverResults(ActivityThread.java:4327)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4370)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread.-wrap19(Unknown Source:0)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1652)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.os.Handler.dispatchMessage(Handler.java:105)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.os.Looper.loop(Looper.java:164)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread.main(ActivityThread.java:6565)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at java.lang.reflect.Method.invoke(Native Method)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
01-01 13:22:35.082 E/AndroidRuntime( 9524): Caused by: java.lang.SecurityException: UID 10095 does not have permission to content://com.android.providers.media.documents/document/audio%3A299 [user 0]; you could obtain access using ACTION_OPEN_DOCUMENT or related APIs
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.os.Parcel.readException(Parcel.java:1942)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.os.Parcel.readException(Parcel.java:1888)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4365)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1612)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.startActivityForResult(Activity.java:4472)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.startActivityForResult(Activity.java:4430)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.startActivity(Activity.java:4791)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.startActivity(Activity.java:4759)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at com.codeaurora.music.custom.PermissionActivity.onRequestPermissionsResult(PermissionActivity.java:127)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7388)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.Activity.dispatchActivityResult(Activity.java:7239)
01-01 13:22:35.082 E/AndroidRuntime( 9524): at android.app.ActivityThread.deliverResults(ActivityThread.java:4323)
01-01 13:22:35.082 E/AndroidRuntime( 9524): ... 9 more
分析解决:根据log:Caused by: java.lang.SecurityException: UID 10095 does not have permission to content://com.android.providers.media.documents/document/audio%3A299 [user 0]; you could obtain access using ACTION_OPEN_DOCUMENT or related APIs,在对应位置给intent添加action,如下
mPreviousIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
推荐阅读
-
【Android】解决savedInstanceState.getString方法为空!
-
Android SDK Manager 打不开的解决方法
-
Android平台上图片/视频选择,编辑和压缩的一站式解决方案
-
PHP session常见问题集锦及解决办法总结_PHP教程
-
Mysql和网页显示乱码解决方法集锦_php技巧
-
android studio 3.0.1依赖butterknife报错问题解决办法以及androidstudio2.0和3.0以上butterknife的配置大全
-
解决Android帧动画在Oncreate中启动只显示第一帧
-
解决Android帧动画在Oncreate中启动只显示第一帧
-
Android开发解决popupWindow重叠报错问题
-
android安装后启动出错解决