Android - Unable to instantiate activity - Class not found exception after upgrading to ADT 22

StackOverflow https://stackoverflow.com/questions/16610296

  •  29-05-2022
  •  | 
  •  

Question

I have recently upgraded my ADT to version 22. After I have done so, I first received an error with my support library (which was relied on another library project). After I have copied the support library to my project and cleaned all my projects, I keep receiving the following errors when I try to launch my application:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.d.d/com.d.d.MainActivity}: java.lang.ClassNotFoundException: com.d.d.MainActivity

(I have renamed the real package name to com.d.d)

But what keeps me suspicious that it is a cause of the support library changes, is the following line:

at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

It keeps me suspicious because when I have messed with the support library before, I received many errors that are related to dex something.

Needless to say, the AndroidManifest contains the correct path for the activity.

Any help will be much appreciated here. Thanks a lot.

Was it helpful?

Solution

Might be a duplicate of this.

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.

OTHER TIPS

@Krauxe Thank you very much for providing this answer!

However, I had to use a slightly adjusted approach in my Eclipse (Version: 3.7.2).

  1. Project - Properties - Java Build Path - Order & Export
  2. Check Android Private Libraries (also for used library projects)
  3. Project - Clean... - Clean all projects

Here, we had to add the src folder as a source folder. For some reason the binding disappeared.

  1. Right click your src folder.
  2. Build Path -> Use as Source Folder

I had the same problem. The solution was to change the output folder to bin/classes.

  1. Right click on the project
  2. Select Properties
  3. Goto Java Build Path > Source
  4. Set Default output folder to /bin/classes

Greetings, Martin

if you've tried all the answers still got the problem then probably the activity name mismatch the package name in AndroidManifest.xml. for example your xml like this.

<activity
    android:name="com.tony.HomeActivity"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

but the HomeActivity actually in the package com.tony.ui.HomeActivity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top