Android:无法实例化活动

时间:2014-11-08 18:19:47

标签: android class android-studio

我无法运行我的应用程序。它突然发生了。有一刻我可以运行我的应用程序,下一个我不能......它给了我例外:

11-08 19:04:42.936  20390-20390/dk.chargesmart.findstroem E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{dk.chargesmart.findstroem/dk.chargesmart.findstroem.MainActivity}: java.lang.IllegalAccessException

在android清单文件中,它表示我的活动不公开

enter image description here

这里是活动的“头部”

class MainActivity extends FragmentActivity {

GoogleMap mMap;
ClusterManager<MyPin> mClusterManager;
ArrayList<Location> mLocations;
boolean showDetail;
boolean menuHidden;
boolean isAnimating;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setUpMapIfNeeded();
    downloadItems();

    menuHidden = false;

    setUpMenu();
}

以下是关于异常的更多信息

11-08 19:04:42.936  20390-20390/dk.chargesmart.findstroem E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{dk.chargesmart.findstroem/dk.chargesmart.findstroem.MainActivity}: java.lang.IllegalAccessException: access to class not allowed
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
        at android.app.ActivityThread.access$700(ActivityThread.java:159)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5419)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalAccessException: access to class not allowed
        at java.lang.Class.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1130)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1078)

1 个答案:

答案 0 :(得分:4)

您的活动应定义为

public class MainActivity extends FragmentActivity {
    ...
    ...
}

关键字公开