在实际的开发中,我遇到过两次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. kuangbin_ShortPath F (POJ 3259)

    判环模板题 有了上一题的经验过得很轻松 除了因为spfa还不是很熟打错了两个字母 然后debug了一小会 #include <iostream> #include <string&g ...

  2. “访问 IIS 元数据库失败”错误的解决方法

    1.依次点击“开始”-“运行”.    2.在“运行”栏内输入 “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i ...

  3. Twsited异步网络框架

    Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如:网络协议.线程.数据库管理.网络操作.电子邮件等. Twisted介绍:http://blog.csdn.net/hanhuili/a ...

  4. Too many authentic authentication failures for root

    连接SSH服务器时报 Too many authentic authentication failures for root. 方法一:删除目标服务器 /root/.ssh/目录下的 known_ho ...

  5. python文件操作--字符串替换

    如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa with open('test.txt','+r') as f: t = f.read() t = d.replace('AAA' ...

  6. Git-rebase与merge小结

    git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 ---------------------- ...

  7. orzdba的安装与使用

    参考:http://code.taobao.org/p/orzdba/src/ http://code.taobao.org/p/myrelay/wiki/index/ http://www.taob ...

  8. WCF Data Service 使用小结 —— 了解OData(一)

    最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...

  9. ABBYY如何把PDF转换Excel

    我们都知道2007以上版本的Office文档,是可以直接将文档转存为PDF格式文档的.那么反过来,PDF文档可以转换成其他格式的文档吗?这是大家都比较好奇的话题.如果可以以其他格式进行保存,就可以极大 ...

  10. 谷歌 analytics.js 部分解密版

    源:http://www.google-analytics.com/analytics.js (function(){var aa=encodeURIComponent,f=window,ba=set ...