gpt4 book ai didi

Android:无法实例化 Activity

转载 作者:行者123 更新时间:2023-11-29 15:57:49 24 4
gpt4 key购买 nike

我在运行我的应用程序时遇到问题。它只是突然发生了。前一刻我可以运行我的应用程序,下一刻我不能..它给了我异常(exception):

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 list 文件中它说我的 Activity 不是公开的

enter image description here

这里是 Activity 的“头”

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)

最佳答案

您的 Activity 应定义为

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

关键字是public

关于Android:无法实例化 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26820476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com