Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

android - Unable to instantiate activity ComponentInfo

I am developing an application for Froyo as minimum version and Gingerbread as the target version. So, the manifest shows:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/>

I have an emulator and a Nexus One with Gingerbread, and the application deploys and installs correctly. But when it starts, it crashes, and the error thrown in the log is:

09-18 06:35:11.240: ERROR/AndroidRuntime(382): FATAL EXCEPTION: main
09-18 06:35:11.240: ERROR/AndroidRuntime(382): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.package/com.my.package.Dashboard}: java.lang.ClassNotFoundException: com.my.package.Dashboard in loader dalvik.system.PathClassLoader[/data/app/com.my.package-2.apk]
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.os.Looper.loop(Looper.java:130)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at java.lang.reflect.Method.invokeNative(Native Method)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at java.lang.reflect.Method.invoke(Method.java:507)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at dalvik.system.NativeStart.main(Native Method)
09-18 06:35:11.240: ERROR/AndroidRuntime(382): Caused by: java.lang.ClassNotFoundException: com.my.package.Dashboard in loader dalvik.system.PathClassLoader[/data/app/com.my.package-2.apk]
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
09-18 06:35:11.240: ERROR/AndroidRuntime(382):     ... 11 more

And yes, the activity "Dashboard" is declared in the Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.my.package"
      android:versionCode="1"
      android:versionName="1.0"
      android:installLocation="auto">

      <activity android:name=".Dashboard"
              android:label="@string/app_name"
              android:screenOrientation="portrait">

            <intent-filter>
                  <action android:name="android.intent.action.MAIN"/>
                  <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
      </activity>

      ...

So what can this problem be related to?? This is driving me nuts.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had this problem as well developing under Eclipse 4.2. My main activity was referenced by the AndroidManifest.xml file, included the correct package and name, but still failed to load. After a bit of debugging and commenting out things, I discovered that an interface that my main activity was implementing was the source of the problem. This interface is defined in a separate project, but I had failed to reference that project in the Java Build Path. So, when I built things, they would build correctly, but I'd immediately encounter a force close when I launched, with the same error as this question.

To correct this, I right-clicked on the Android project, selected Java Build Path, added my 'common code' project to the Projects tab and then checked the box for that same project on the Order and Export tab. After that, everything worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...