以下为错误日志:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {.ui.main.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.deliverResults(ActivityThread.java:4089)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1616)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5917)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:351)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:320)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:281)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
at android.support.v7.app.AlertController.installContent(AlertController.java:214)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:258)
at android.app.Dialog.dispatchOnCreate(Dialog.java:404)
at android.app.Dialog.show(Dialog.java:301)
at .util.EasyPermissionsUtil.checkDeniedPermissionsNeverAskAgain(EasyPermissionsUtil.java:264)
at .util.EasyPermissionsUtil.checkDeniedPermissionsNeverAskAgain(EasyPermissionsUtil.java:221)
at .base.ExBaseActivity.onPermissionsDenied(ExBaseActivity.java:391)
at .util.EasyPermissionsUtil.onRequestPermissionsResult(EasyPermissionsUtil.java:196)
at .base.ExBaseActivity.onRequestPermissionsResult(ExBaseActivity.java:406)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6638)
at android.app.Activity.dispatchActivityResult(Activity.java:6516)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1616)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5917)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
今天在开发时遇到这个异常,查了一些资料,有说让修改父类为activity的,有说修改自己的主题的,我的界面父类是FragmentActivity,我不想修改它,也不想随便改主题,别人也没说原因,很郁闷,自己继续埋头研究,我debug时确认是在弹出一个AlertDialog时程序崩溃的,但是AlertDialog的用法我也确认是对的,陷入抓狂中....然后想到他们的解决方案是修改父类去适应自己的应用场景,那我的问题肯定是应用场景不适用与当前的父类,在上面的日志中有关于AlertDialog的报错,而且debug时也确定是是AlertDialog的问题,我就猜测是不是导入的包的问题,因为我的父类是v4下的,而我导入的AlertDialog的包是v7下的。有了怀疑对象就行动起来,重新导包发现果然有两个包,这次选择了android.app下的,重新编译运行,完美解决。果然是导入包类别不一致的问题。
总结:出现此问题的诱因有很多,可以根据自身的场景判断原因,解决方案:
1:修改自己的父类为activity
2:在style下修改自己的主题:主题为Theme.AppCompat下的主题 如:<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
3:就是使用与类似我的情况了,修改自己所用控件的包。
根据自己情况徐泽适合方案,多动脑,少烦恼。