17

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.

MrByte
  • 1,083
  • 2
  • 11
  • 21

5 Answers5

83

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.

Community
  • 1
  • 1
Krauxe
  • 6,058
  • 2
  • 24
  • 22
  • Yea this solved it for me too. Looks like the contents of your libs/ folder is now quasi-compiled under Android Private Libraries... except when you update to the new ADT you need to check that in Project Properties or else it won't be included in the compile. Android Studio here we come – JMRboosties May 17 '13 at 17:33
  • Thanks it worked. Just a question though, what happens when we check any particular library? Even the SDK is being used to compile but it isn't checked. – Basit Ali May 24 '13 at 07:08
  • ( please help me with java.lang.NoClassDefFoundError: my.package.AMainActivity$UpdateTask ) my adt is 21 with Android Private Libraries checked by default, but still so many exceptions. Why? – thecr0w Dec 05 '14 at 03:14
  • 1
    Does anyone know how to fix this in an IntelliJ / Android Studio Gradle setup? – Will Calderwood Mar 27 '15 at 22:52
  • @WillCalderwood Have you found solution for Android Studio? – user1483208 Apr 24 '15 at 13:07
  • @user1483208 I'm afraid not. I now always do a clean before doing a release build that seems to have improved the situation. It's not solved it completely though. – Will Calderwood Apr 24 '15 at 13:10
6

@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
droide_91
  • 197
  • 2
  • 6
1

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
Julio Rodrigues
  • 3,373
  • 3
  • 24
  • 33
  • Wow, I spent so long trying to figure this out. I kept finding the answers given above, but your solution is what I really needed. I wanted to update my app after a long break, so maybe that's why the setup changed slightly (how annoying!). Thanks. :D – Tony Wickham Mar 04 '14 at 07:21
0

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

0

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.

SalutonMondo
  • 629
  • 9
  • 17