5

I am learning the tutorial from the android web site.

But when I run the application, it prompts Unable to instantiate activity component, something about the classNotFoundException. But in the manifext.xml file the MainActivity was registered. I don't know where is the problem. Here is the full error log.

05-03 18:59:00.425: E/AndroidRuntime(20858): FATAL EXCEPTION: main
05-03 18:59:00.425: E/AndroidRuntime(20858): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.effectivenavigation/com.example.android.effectivenavigation.MainActivity}: java.lang.ClassNotFoundException: com.example.android.effectivenavigation.MainActivity
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.os.Looper.loop(Looper.java:137)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread.main(ActivityThread.java:4745)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at java.lang.reflect.Method.invokeNative(Native Method)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at java.lang.reflect.Method.invoke(Method.java:511)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at dalvik.system.NativeStart.main(Native Method)
05-03 18:59:00.425: E/AndroidRuntime(20858): Caused by: java.lang.ClassNotFoundException: com.example.android.effectivenavigation.MainActivity
05-03 18:59:00.425: E/AndroidRuntime(20858):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
05-03 18:59:00.425: E/AndroidRuntime(20858):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
05-03 18:59:00.425: E/AndroidRuntime(20858):    ... 11 more

manifest file, AbdroidManifest.xml

<!--
  Copyright 2012 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

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

    <uses-sdk android:minSdkVersion="14" />

    <application android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@android:style/Theme.Holo.Light.DarkActionBar">

        <activity android:name=".MainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".CollectionDemoActivity" android:label="@string/demo_collection" />

    </application>
</manifest>
Jolin
  • 1,515
  • 4
  • 21
  • 24

2 Answers2

10

If I'm not mistaken you are using Android Support Library. How did you add it to your project? If you added in Java Build Path you might face this exception.

A suggestion would be to remove the JAR from your build path and just right click on your project and choose Android Tools --> Add Support Library.

Sam R.
  • 16,027
  • 12
  • 69
  • 122
  • I tried with Add Support Library, but still not working. Any other idea ? I'm using a Nexus One with android 2.3.3 to test – vrunoa Sep 26 '13 at 19:49
  • I needed to add to the section of the manifest file. An error stating to do this exactly might be in your logcat output. – Phil Mar 04 '14 at 17:45
0

Most likely reference to your activity .xml is not found or the names do not match with the one in the Android manifest .xml file. You may want to post your code for a better answer.

user2347763
  • 469
  • 2
  • 10
  • Is this a second activity that you are starting ? Please check if the res/layouts/activity.xml filename and the Activity.java class name matches with the above. If it still does not work, post your activity.xml code and the .java code. – user2347763 May 03 '13 at 18:10
  • Strange problem because with min-sdk "14" (and if you have created an Android Application Project with Eclipse) there is no need to add any Support Library manually even if you use a GridLayout! Glad to know that your problem is solved, though! – user2347763 May 03 '13 at 18:28