简体   繁体   English

java.lang.RuntimeException:无法实例化活动

[英]java.lang.RuntimeException: Unable to instantiate activity

how can I fix bellow errors from my logcat 如何从我的logcat修复波纹管错误

   java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{hesh.ballc/hesh.ballc.MainActivity}: java.lang.IllegalAccessException: hesh.ballc.MainActivity() is not accessible from class android.app.Instrumentation
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)    



Caused by: java.lang.IllegalAccessException: hesh.ballc.MainActivity() is not accessible from class android.app.Instrumentation
        at java.lang.Class.newInstance(Class.java:1603)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)

There is no errors in code as I can see, after running my program it stops in my emulator and I get bellow errors, should I import some libary ? 我可以看到代码中没有错误,运行我的程序后它停止在我的模拟器中,我得到了错误,我应该导入一些库吗?

According to the stack trace, you implemented a constructor on hesh.ballc.MainActivity . 根据堆栈跟踪,您在hesh.ballc.MainActivity上实现了一个构造hesh.ballc.MainActivity

DO NOT DO THIS . 不要这样做 There are few, if any, scenarios in which having a constructor on an Activity subclass is the appropriate thing to do. 很少(如果有的话)在Activity子类上有构造函数的场景是适当的。

Whatever code you have in that constructor should go into the activity's onCreate() method, probably after the super.onCreate() call. 无论你在构造函数中拥有什么代码,都应该进入activity的onCreate()方法,可能是在super.onCreate()调用之后。

There was another case of this occurring not covered that I thought I would provide details for. 还有另一个案例没有涉及,我想我会提供详细信息。 When you have library dependencies and import modules, be sure that the other libraries do not have a manifest file that lists the module as a launchable component. 当您具有库依赖项和导入模块时,请确保其他库没有将模块列为可启动组件的清单文件。

This might be an oddity to have this in a library, but if it finds itself in there (from instance, following a default start of a project) then you simply need to remove the offending module's manifest launcher component and reimport the module. 在库中使用它可能很奇怪,但是如果它在那里(从实例,在项目的默认启动之后)发现它,那么你只需要删除有问题的模块的清单启动器组件并重新导入模块。

You will see a similar stacktrace exception as indicated above in the post, but it will reference a class that is not the main project (a library module project trying to be launched). 您将在帖子中看到类似的stacktrace异常,但它将引用一个不是主项目的类(一个试图启动的库模块项目)。 It seems to merge some manifest files and if setup improperly you may get this behavior. 它似乎合并了一些清单文件,如果设置不正确,您可能会遇到此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException: Unable to instantiate activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException: Unable to instantiate the activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException:Unable to instantiate activity java.lang.RuntimeException:无法实例化活动 ComponentInfo - 不是搜索活动 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - not search activity java.lang.RuntimeException:无法实例化活动ComponentInfo - NFC访问 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - NFC access 错误:java.lang.RuntimeException:无法实例化活动 - Error: java.lang.RuntimeException: Unable to instantiate activity java.lang.RuntimeException:无法实例化活动错误 - java.lang.RuntimeException: Unable to instantiate activity error java.lang.RuntimeException:无法为 Kotlin MainActivity 实例化活动 ComponentInfo - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo for Kotlin MainActivity java.lang.RuntimeException:无法实例化活动…(Android Studio) - java.lang.RuntimeException: Unable to instantiate activity…(android studio) java.lang.RuntimeException:无法实例化活动ComponentInfo(PhoneGap) - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo (PhoneGap)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM