实例化异常:没有空构造函数



当我启动应用程序时,我的Android应用程序中不断出现以下错误:

10-07 22:00:07.416  21555-21555/com.antechdevelopment.NotificationReminders E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.antechdevelopment.NotificationReminders, PID: 21555
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.antechdevelopment.NotificationReminders/com.antechdevelopment.NotificationReminders.screens.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.antechdevelopment.NotificationReminders.screens.MainActivity$NewReminderFragment: make sure class name exists, is public, and has an empty constructor that is public
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.antechdevelopment.NotificationReminders.screens.MainActivity$NewReminderFragment: make sure class name exists, is public, and has an empty constructor that is public
            at android.support.v4.app.Fragment.instantiate(Fragment.java:413)
            at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
            at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1790)
            at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
            at com.antechdevelopment.NotificationReminders.screens.MainActivity.onCreate(MainActivity.java:96)
            at android.app.Activity.performCreate(Activity.java:5426)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.InstantiationException: can't instantiate class com.antechdevelopment.NotificationReminders.screens.MainActivity$NewReminderFragment; no empty constructor
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1208)
            at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
            at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
            at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1790)
            at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
            at com.antechdevelopment.NotificationReminders.screens.MainActivity.onCreate(MainActivity.java:96)
            at android.app.Activity.performCreate(Activity.java:5426)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)

然而,我显然有一个空的构造函数???这是它所指的代码:

public class NewReminderFragment extends Fragment {
    public NewReminderFragment() {
    }
    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.new_reminder_fragment, container, false);
        ...
        return rootView;
    }
}

有人有什么想法吗???这真的很烦人,发布也不好!

我做了研究,但没有用。

将片段声明为静态:

public static class NewReminderFragment extends Fragment

相关内容

  • 没有找到相关文章

最新更新