How to Solve Error: Unable to instantiate activity ComponentInfo

Today, I encountered a bug like this:

java.lang.RuntimeException:UnabletoinstantiateactivityComponentInfo{cn.xs8.app/cn.xs8.app.activity.xs8_HelpActivity}:java.lang.ClassNotFoundException:cn.xs8.app.activity.xs8_HelpActivity
	atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
	atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
	atandroid.app.ActivityThread.access$600(ActivityThread.java:130)
	atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
	atandroid.os.Handler.dispatchMessage(Handler.java:99)
	atandroid.os.Looper.loop(Looper.java:137)
	atandroid.app.ActivityThread.main(ActivityThread.java:4745)
	atjava.lang.reflect.Method.invokeNative(NativeMethod)
	atjava.lang.reflect.Method.invoke(Method.java:511)
	atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
	atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
	atdalvik.system.NativeStart.main(NativeMethod)
Causedby:java.lang.ClassNotFoundException:cn.xs8.app.activity.xs8_HelpActivity
	atdalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
	atjava.lang.ClassLoader.loadClass(ClassLoader.java:501)
	atjava.lang.ClassLoader.loadClass(ClassLoader.java:461)
	atandroid.app.Instrumentation.newActivity(Instrumentation.java:1053)
	atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
	...11more

After searching, we know that the activity was originally registered in the manifest. XML list, but the activity has been deleted

The following is a summary of three situations in which an activity cannot be instantiated:

1. The activity is not registered in the manifest.xml list, or the package name or the class name of the activity is modified after the activity is created, but not in the configuration list, so it cannot be instantiated

2. You create a new package and still use the default package when registering. For example, the default package is com.ghg.dao package. You create a new com.ghg.daoimpl package and write a firstactivity in it. When registering in manifest.xml, you write & lt; activity android:name= “.FirstActivity”/>, At this time, it means that your class is registered in the default package. The system can’t find it in the default package. Because your firstactivity is under the com.ghg.daoimpl package, you should write the package name and class name when you register, such as: & lt; activity android:name= “com.ghg.DaoImpl.FirstActivity”; In this way, the system can find the corresponding class in the specified package

3. Another way is to define your firstactivity as an abstract class, which seems that most people will not make

If the above three cases are taken into account and this exception will be thrown, check whether the constructor and oncreate () of this class exist in the activity class at the same time. If so, try deleting the constructor and placing the initialization in the

Try oncreate()

 

Similar Posts: