2013-09-24 67 views
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 

} 
} 

有人可以幫我找出問題所在嗎?

謝謝。

回答

0

檢查這個錯誤訊息

造成的:java.lang.IllegalAccessException:訪問構造不允許 在java.lang.Class.newInstanceImpl(本機方法) 在java.lang.Class.newInstance (Class.java:1319) 在android.support.v4.app.Fragment.instantiate(Fragment.java:384)

你有一個名爲的newInstance()函數?如果是這樣,請發佈代碼。 請查看關於如何使用DialogFragments的示例。 DialogFragments

0

可能你有你的ProgressDialogFragment類的私有或受保護的默認構造函數。使其公開或更好地移除構造函數,並使用onCreate()來初始化變量。