博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unable to instantiate fragment make sure class nam
阅读量:6212 次
发布时间:2019-06-21

本文共 4003 字,大约阅读时间需要 13 分钟。

今天突然遇到一个fragment的Bug,研究了好久~~ 还是google解决问题

E/UncaughtException-main(13661): Unable to start activity ComponentInfo{com.android.fileexplorer/com.android.fileexplorer.FileExplorerTabActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.fileexplorer.view.FileViewFragment: make sure class name exists, is public, and has an empty constructor that is public
E/UncaughtException-main(13661): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.fileexplorer/com.android.fileexplorer.FileExplorerTabActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.fileexplorer.view.FileViewFragment: make sure class name exists, is public, and has an empty constructor that is public
E/UncaughtException-main(13661):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
E/UncaughtException-main(13661):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/UncaughtException-main(13661):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
E/UncaughtException-main(13661):     at android.app.ActivityThread.access$900(ActivityThread.java:135)
E/UncaughtException-main(13661):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
E/UncaughtException-main(13661):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/UncaughtException-main(13661):     at android.os.Looper.loop(Looper.java:136)
E/UncaughtException-main(13661):     at android.app.ActivityThread.main(ActivityThread.java:5017)
E/UncaughtException-main(13661):     at java.lang.reflect.Method.invokeNative(Native Method)
E/UncaughtException-main(13661):     at java.lang.reflect.Method.invoke(Method.java:515)
E/UncaughtException-main(13661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/UncaughtException-main(13661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/UncaughtException-main(13661):     at dalvik.system.NativeStart.main(Native Method)
E/UncaughtException-main(13661): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.fileexplorer.view.FileViewFragment: make sure class name exists, is public, and has an empty constructor that is public
E/UncaughtException-main(13661):     at android.app.Fragment.instantiate(Fragment.java:601)
E/UncaughtException-main(13661):     at android.app.FragmentState.instantiate(Fragment.java:98)
E/UncaughtException-main(13661):     at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1761)
E/UncaughtException-main(13661):     at android.app.Activity.onCreate(Activity.java:899)
E/UncaughtException-main(13661):     at miui.app.Activity.onCreate(Activity.java:48)
E/UncaughtException-main(13661):     at com.android.fileexplorer.FileExplorerTabActivity.onCreate(FileExplorerTabActivity.java:39)
E/UncaughtException-main(13661):     at android.app.Activity.performCreate(Activity.java:5231)
E/UncaughtException-main(13661):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/UncaughtException-main(13661):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/UncaughtException-main(13661):     ... 12 more
E/UncaughtException-main(13661): Caused by: java.lang.InstantiationException: can't instantiate class com.android.fileexplorer.view.FileViewFragment; no empty constructor
E/UncaughtException-main(13661):     at java.lang.Class.newInstanceImpl(Native Method)
E/UncaughtException-main(13661):     at java.lang.Class.newInstance(Class.java:1208)
E/UncaughtException-main(13661):     at android.app.Fragment.instantiate(Fragment.java:590)
E/UncaughtException-main(13661):     ... 20 more
解决方法:自定义的fragment最好有一个Public的参数为空的构造函数,若需要传入一个参数,可以使用下面的方法
public FileViewFragment(){    }
 public static FileViewFragment getInstance(A a){
        FileViewFragment fileViewFragment = new FileViewFragment();
        fileViewFragment.a = a;
        return fileViewFragment;
    }

转载于:https://my.oschina.net/tingzi/blog/222178

你可能感兴趣的文章
Jieba分词Python简单实现
查看>>
fastcgi与php-fpm
查看>>
CCNP路由-17 BGP基本配置及维护
查看>>
Android Studio 下使用JNI运行hello word程序
查看>>
windows查看端口占用
查看>>
java性能监控
查看>>
老李分享:java线程生命周期 2
查看>>
一个强大专业的响应式jQuery幻灯效果插件:Royal Slider
查看>>
Formal Languages and Compilers-LL(1),FIRST and FOLLOW
查看>>
ThinkPHP源码学习---is_ssl() 函数 判断是否SSL协议
查看>>
PyOdps在交互式环境下的使用,让探索ODPS数据更容易些
查看>>
聊聊netflix的EurekaHttpClient
查看>>
聊聊flink Table的select操作
查看>>
单臂路由
查看>>
作业 第一章
查看>>
第一次作业
查看>>
我的友情链接
查看>>
康盛系列产品工程师php
查看>>
Excel利用超链接打开指定文件夹
查看>>
Elasticsearch走上专案专有化 AWS:将另开辟开放版
查看>>