Unable to instantiate fragment XXX make sure class name exists, is public, and has an empty constru

9 D AndroidRuntime: Shutting down VM
03-13 14:03:00.341587 30529 30529 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41d1ece0)
03-13 14:03:00.341591 30529 30529 W dalvikvm: threadid=1: uncaught exception occurred
03-13 14:03:00.341658 30529 30529 W System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.dialer/com.android.dialer.DialtactsActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.mediatek.dialer.calllogex.CallLogFragmentEx: make sure class name exists, is public, and has an empty constructor that is public
03-13 14:03:00.341796 30529 30529 W System.err: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
03-13 14:03:00.341816 30529 30529 W System.err: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
03-13 14:03:00.341834 30529 30529 W System.err: 	at android.app.ActivityThread.access$800(ActivityThread.java:151)
03-13 14:03:00.341849 30529 30529 W System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
03-13 14:03:00.341864 30529 30529 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:110)
03-13 14:03:00.341878 30529 30529 W System.err: 	at android.os.Looper.loop(Looper.java:193)
03-13 14:03:00.341891 30529 30529 W System.err: 	at android.app.ActivityThread.main(ActivityThread.java:5299)
03-13 14:03:00.341912 30529 30529 W System.err: 	at java.lang.reflect.Method.invokeNative(Native Method)
03-13 14:03:00.341927 30529 30529 W System.err: 	at java.lang.reflect.Method.invoke(Method.java:515)
03-13 14:03:00.341941 30529 30529 W System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
03-13 14:03:00.341955 30529 30529 W System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
03-13 14:03:00.341969 30529 30529 W System.err: 	at dalvik.system.NativeStart.main(Native Method)
03-13 14:03:00.342011 30529 30529 W System.err: Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.mediatek.dialer.calllogex.CallLogFragmentEx: make sure class name exists, is public, and has an empty constructor that is public
03-13 14:03:00.342929 30529 30529 W System.err: 	at android.app.Fragment.instantiate(Fragment.java:601)
03-13 14:03:00.342950 30529 30529 W System.err: 	at android.app.FragmentState.instantiate(Fragment.java:98)
03-13 14:03:00.342968 30529 30529 W System.err: 	at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1759)
03-13 14:03:00.342984 30529 30529 W System.err: 	at android.app.Activity.onCreate(Activity.java:899)
03-13 14:03:00.343006 30529 30529 W System.err: 	at com.android.contacts.common.activity.TransactionSafeActivity.onCreate(TransactionSafeActivity.java:32)
03-13 14:03:00.343021 30529 30529 W System.err: 	at com.android.dialer.DialtactsActivity.onCreate(DialtactsActivity.java:395)
03-13 14:03:00.343036 30529 30529 W System.err: 	at android.app.Activity.performCreate(Activity.java:5264)
03-13 14:03:00.343052 30529 30529 W System.err: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
03-13 14:03:00.343066 30529 30529 W System.err: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
03-13 14:03:00.343086 30529 30529 W System.err: 	... 11 more
03-13 14:03:00.343107 30529 30529 W System.err: Caused by: java.lang.InstantiationException: can't instantiate class com.mediatek.dialer.calllogex.CallLogFragmentEx; no empty constructor
03-13 14:03:00.343226 30529 30529 W System.err: 	at java.lang.Class.newInstanceImpl(Native Method)
03-13 14:03:00.343242 30529 30529 W System.err: 	at java.lang.Class.newInstance(Class.java:1215)
03-13 14:03:00.343257 30529 30529 W System.err: 	at android.app.Fragment.instantiate(Fragment.java:590)
03-13 14:03:00.343269 30529 30529 W System.err: 	... 19 more
03-13 14:03:00.343281 30529 30529 W dalvikvm: threadid=1: calling UncaughtExceptionHandler

我是 直接加了fragment构造方法,CallLogFragmentEx   mCallLogFragmentEx  =  new  mCallLogFragmentEx(true);导致报错

解决方法:自定义的fragment最好有一个Public的参数为空的构造函数,若需要传入一个参数,可以使用下面的方法
public FileViewFragment(){    }
 public static FileViewFragment getInstance(A a){
        FileViewFragment fileViewFragment = new FileViewFragment();
        fileViewFragment.a = a;
        return fileViewFragment;
    }

你可能感兴趣的:(Unable to instantiate fragment XXX make sure class name exists, is public, and has an empty constru)