1

我已经查看了相同错误的问题,但我正在实施答案中给出的所有解决方案,但我的 logcat 中出现以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.overview.LoginActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.test.base.BaseActivity$ProgressDialogFragment: make sure class name exists, is public, and has an empty constructor that is public
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
    at android.app.ActivityThread.access$700(ActivityThread.java:143)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4950)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.mint.test.base.BaseActivity$ProgressDialogFragment: make sure class name exists, is public, and has an empty constructor that is public
    at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
    at android.support.v4.app.FragmentState.instantiate(Fragment.java:96)
    at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1726)
    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:198)
    at com.mint.test.base.BaseActivity.onCreate(BaseActivity.java:88)
    at com.mint.test.base.BaseActivity.onCreate(BaseActivity.java:84)
    at com.test.base.FlipperActivity.onCreate(FlipperActivity.java:56)
    at com.test.overview.LoginActivity.onCreate(LoginActivity.java:99)
    at android.app.Activity.performCreate(Activity.java:5179)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
    ... 11 more
Caused by: java.lang.IllegalAccessException: access to constructor not allowed
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1319)
    at android.support.v4.app.Fragment.instantiate(Fragment.java:384)
    ... 21 more

在我的代码中,我有以下内容:

@SuppressLint({ "ValidFragment", "UseSparseArrays" })
public abstract class BaseActivity extends FragmentActivity {

//The class is static and public
public static class ProgressDialogFragment extends DialogFragment {

    public ProgressDialogFragment() {} //Empty Constructor

 }
}

有人可以帮我确定问题所在吗?

谢谢。

4

2 回答 2

1

检查此错误消息

原因:java.lang.IllegalAccessException:在 android.support.v4.app 的 java.lang.Class.newInstance(Class.java:1319) 的 java.lang.Class.newInstanceImpl(Native Method) 不允许访问构造函数。 Fragment.instantiate(Fragment.java:384)

你有一个名为 newInstance() 的函数吗?如果是这样,请发布代码。查看此示例以了解如何使用 DialogFragments。对话片段

于 2013-09-24T01:51:30.743 回答
0

可能您有 ProgressDialogFragment 类的私有或受保护的默认构造函数。将其公开或完全删除构造函数,并使用 onCreate() 初始化本地变量。

于 2013-10-22T05:22:21.283 回答