在实际的开发中,我遇到过两次android.app.Fragment$InstantiationException报错。

其中一次报错,根据报错提示 “make sure class name exists, is public, and has an empty constructor that is public” ,若Fragement定义有带参构造函数,则一定要定义public的默认的构造函数。即可解决此问题。如果硬要携带参数进去,可以通过Intent结合Bunble的方式携带进去。

第二次报错如下贴的log信息,在“is public, and has an empty constructor that is public” 都满足的情况下,编译ENG版本运行没有任何问题,但是编译USER版本就会出现CRASH错误。原因在于USER版本编译时会代码混淆。

E/AndroidRuntime( 3253): FATAL EXCEPTION: main

E/AndroidRuntime( 3253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.SubSettings}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.settings.mcwill.McWiLLSettings: make sure class name exists, is public, and has an empty constructor that is public

E/AndroidRuntime( 3253):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1964)
E/AndroidRuntime( 3253):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
E/AndroidRuntime( 3253):     at android.app.ActivityThread.access$600(ActivityThread.java:126)
E/AndroidRuntime( 3253):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1155)
E/AndroidRuntime( 3253):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3253):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3253):     at android.app.ActivityThread.main(ActivityThread.java:4482)
E/AndroidRuntime( 3253):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3253):     at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3253):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
E/AndroidRuntime( 3253):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
E/AndroidRuntime( 3253):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3253): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.settings.mcwill.McWiLLSettings: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime( 3253):     at android.app.Fragment.instantiate(Fragment.java:581)
E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.switchToHeaderInner(PreferenceActivity.java:1120)
E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.switchToHeader(PreferenceActivity.java:1136)
E/AndroidRuntime( 3253):     at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:532)
E/AndroidRuntime( 3253):     at com.android.settings.Settings.onCreate(Settings.java:99)
E/AndroidRuntime( 3253):     at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 3253):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 3253):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
E/AndroidRuntime( 3253):     ... 11 more
E/AndroidRuntime( 3253): Caused by: java.lang.ClassNotFoundException: com.android.settings.mcwill.McWiLLSettings
E/AndroidRuntime( 3253):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime( 3253):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 3253):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 3253):     at android.app.Fragment.instantiate(Fragment.java:571)
E/AndroidRuntime( 3253):     ... 18 more
W/ActivityManager(  422):   Force finishing activity com.android.settings/.SubSettings
W/ActivityManager(  422):   Force finishing activity com.android.settings/.Settings

        解决办法:

在对应模块的proguard.flags文件中引入该Fragment所在的类包即可。比如: -keep class com.android.settings.wifi.*Settings

bug_ _ _android.app.Fragment$InstantiationException 解决办法的更多相关文章

  1. 关于android studio 出现Error:Execution failed for task ':app:preDebugAndroidTestBuild'. 的解决办法

    Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 2018年 ...

  2. 20190415 - iOS11 无法连接到 App Store 的解决办法

    问题:更新 iOS 11 后,打开 App Store 提示: 无法连接至 app store 解决: 进入 iOS 系统[设置][iTunes Store 与 App Store],退出当前登录用户 ...

  3. xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer)解决办法

    背景 mac下卸载了xcode,使用git等命令时就提示错误.invalid active path(Applications/Xcode.app/Contents/Developer),这种情况可以 ...

  4. 微信小程序报“app.json”错误解决办法

    1.亲测 “app.json未找到入口 app.json 文件,或者文件读取失败,请检查后重新编译.” 是由于新创建的界面xxx.json所在的文件夹为0KB造成的,你可以试着在xxx.json文件内 ...

  5. Android cannot be cast to android.app.Fragment

    10-21 17:33:45.171: E/AndroidRuntime(7644): java.lang.RuntimeException: Unable to start activity Com ...

  6. Spark Shell启动时遇到<console>:14: error: not found: value spark import spark.implicits._ <console>:14: error: not found: value spark import spark.sql错误的解决办法(图文详解)

    不多说,直接上干货! 最近,开始,进一步学习spark的最新版本.由原来经常使用的spark-1.6.1,现在来使用spark-2.2.0-bin-hadoop2.6.tgz. 前期博客 Spark ...

  7. Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法

    1.必须用Chrome打开 2.在mac电脑上,可能Chrome打开也是空白,解决办法是:在chrome地址栏中输入”chrome:tracing”,然后点击load按钮load你的trace.htm ...

  8. Xcode 7 App Transport Security has blocked a cleartext HTTP 报错解决办法

    Xcode 7 创建新项目用到 UIWebView 发送请求时,报下面的错: “App Transport Security has blocked a cleartext HTTP (http:// ...

  9. Xcode 6.3.2 提交APP(Upload Archive)时崩溃的解决办法

    最近在上传为客户做的APP时,发现Xcode总会在进行到Upload Archive这一步时崩溃,导致APP上载不了.下面说说网上搜索到的几种解决办法. 方法一 亲测有效,很简单: 1.重新打开Xco ...

随机推荐

  1. img元素底部有空白间距的问题

    <div style="width:100px;height:100px"><img src="./1.jpg"></div> ...

  2. java定时框架:表达式设置

    Quartz中时间表达式的设置-----corn表达式 (注:这是让我看比较明白的一个博文,但是抱歉,没有找到原作者,如有侵犯,请告知) 时间格式: <!-- s m h d m w(?) y( ...

  3. awesome-nlp

    awesome-nlp  A curated list of resources dedicated to Natural Language Processing Maintainers - Keon ...

  4. XML中CDATA及其字符实体的使用

    在写xml文档时,偶尔会用到一些特殊字符,如<.>.&等,如下面这段程序: <?xml version="1.0"?> <y>if x& ...

  5. A Flock Of Tasty Sources On How To Start Learning High Scalability

    This is a guest repost by Leandro Moreira. When we usually are interested about scalability we look ...

  6. Java实现一个字符串的反转

    Java小程序实现字符串的反转: 方法一: public class reverseString { public static void main(String[] args) { String s ...

  7. 可选的Web Components类库

    首先需要说明的是这不是一篇 Web Components 的科普文章,如果对此了解不多推荐先读<A Guide to Web Components>. 有句古话-“授人以鱼,不如授人以渔” ...

  8. CentOs6.5中安装和配置vsftp

    一.vsftp安装篇 复制代码代码如下: # 安装vsftpdyum -y install vsftpd# 启动service vsftpd start# 开启启动chkconfig vsftpd o ...

  9. web前端-面试经验总结

    这几次面试主要是冲着百度去的 面试1的主要问题: 笔试: 1.解释css盒子模型 2.常用选择器,以及优先级 3.B如何继承A 4.写一个闭包实例,有什么优点缺点 5.html5的心特性有哪些 6. ...

  10. eclipse开发Android程序sdk和avd的图标不见了

    在eclipse中开发我们的Android程序时,安装sdk是必不可少的,有时候会出现sdk和avd的图标都不见了的情况,一般出现这种情况的原因是你从别处copy了一个sdk的包然后直接在引用造成的, ...