Eclipse and Android with Maven: Unable to instantiate activity ComponentInfo with java.lang.ClassNotFoundException

1.9k views Asked by At

I've got one issue with Eclipse.

There is an android project configured with Maven. Here is pom.xml from child project (all versioning configuration was moved o parent pom.xml):

<dependency>
    <groupId>android.support</groupId>
    <artifactId>compatibility-v4</artifactId>
</dependency>
<dependency>
    <groupId>android.support</groupId>
    <artifactId>compatibility-v7-appcompat</artifactId>
         <type>apklib</type>
</dependency>
<dependency>
     <groupId>android.support</groupId>
     <artifactId>compatibility-v7-appcompat</artifactId>
         <type>jar</type>
</dependency>

Also there is mavenised compatibility-v7-appcompat project imported into workspace as a Library. This project was copied into workspace (because there is an issue with libraries on other locations) and imported to my maven project (Properties -> Android -> Libraries).

I've got one Activity.

public class HelloActivity extends ActionBarActivity

Now I've got an error when i try to debug application:

01-02 13:36:22.753: E/AndroidRuntime(11867): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{somepackage.android/somepackage.android.hello.activities.HelloActivity}:
java.lang.ClassNotFoundException: somepackage.android.hello.activities.HelloActivity in loader dalvik.system.PathClassLoader[/data/app/somepackage.android-2.apk]

I tried everything from other questions. Order & Export in Build Path in both projects and still nothing (Adding libraries with resources Using Eclipse from here: http://developer.android.com/tools/support-library/setup.html)

When I change it to

public class HelloActivity extends FragmentActivity

It works properly, even if I leave AppCompat style in AndroidManifest:

<activity
    android:name="somepackage.android.hello.activities.HelloActivity"
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
    android:windowSoftInputMode="stateHidden|adjustResize" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

What is more, I get an error when app is loaded on device:

[2014-01-02 13:36:19 - compatibility-v7-appcompat] Could not find compatibility-v7-appcompat.apk!

Even thought this project has "Is Library" checkbox set in android properties.

This is how the project looks like: project

I would appreciate help :)

2

There are 2 answers

2
CoolMonster On BEST ANSWER

Check whether the package is selected under java build path->order/export. If its not select then select. if a library is not select under this list there will no error at build time. when run the project specific package will not exported with that project this will cause ClassNotFoundException

1
Marian Przyszedł On

Thanks to CoolMonster I resolved it by doing like this:

  • In mavenised compatibility-v7-appcompat project
    • Project -> Properties -> Order and Export -> select only android-support-v7-appcompat.jar
  • In my project
    • Project -> Properties -> Order and Export -> select Maven Dependencies, Android Private Libraries and Android Dependencies.