在实际的开发中,我遇到过两次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. 越狱Season 1-Episode 13: End of the Tunnel

    Season 1, Episode 13: End of the Tunnel -Fernando: The name is John Abruzzi. 名字是John Abruzzi A b r u ...

  2. VS2013远程调试功能

    我跪了,我真的跪了. 实际证明这是不可行的. [开发机] Win10,64bits,VS2013 [目标机] Winxp VS2013的debug tool不能在xp上安装运行,卒! 如果有win7, ...

  3. (转)8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset

    8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset by Jason Brownlee on August ...

  4. javascript prototype和__proto__

    < script type = "text/javascript" >function Person() { // 属性 this.head = 1; this.eye ...

  5. SQL Server 表所在的文件组

    SELECT  o.[name] ,-- o.[type], i.[name], i.[index_id],         f.[name] FROM    sys.indexes i        ...

  6. ASP.NET会话(Session)保存模式--终于知道session为什么丢失了

    [原创]ASP.NET会话(Session)保存模式 作者:寒羽枫(cityhunter172) 大家好,已有四个多月没写东东啦.今日抽空就说一下 Session 在 .Net v1.0/v1.1 中 ...

  7. linux服务之crond

    use the following command add entries to crontab should take effect right away. right away(立即,立刻) #c ...

  8. 【转】asp.net导出数据到Excel的三种方法

    来源:http://www.cnblogs.com/lishengpeng1982/archive/2008/04/03/1135490.html 原文出处:http://blog.csdn.net/ ...

  9. html之p标签

    p标签定义段落 p元素会自动在其前后创建一些空白,浏览器会自动添加这些空间. 效果图:

  10. VS 2010 编译安装 boost 库 -(和 jsoncpp 库共存)

    boost库的简单应用很容易,网上有很多资料,但是,如果要json 和 boost 一起使用就会出现这样那样的问题, 有时候提示找不到 “libboost_coroutine-vc100-mt-sgd ...