我已经查看了相同错误的问题,但我正在实现答案中给出的所有解决方案,但我在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
}
}
有人可以帮我确定问题所在吗?
感谢。
答案 0 :(得分:0)
检查此错误消息
引起:java.lang.IllegalAccessException:不允许访问构造函数 at java.lang.Class.newInstanceImpl(Native Method) 在java.lang.Class.newInstance(Class.java:1319) 在android.support.v4.app.Fragment.instantiate(Fragment.java:384)
你有一个名为newInstance()的函数吗?如果是这样,请发布代码。 请查看此示例,了解如何使用DialogFragments。 DialogFragments
答案 1 :(得分:0)
您可能拥有ProgressDialogFragment类的私有或受保护的默认构造函数。公开或更好地删除构造函数,并使用onCreate()初始化lical变量。