I am using the m2eclipse plugin in Eclipse Juno, with JDK 1.7 (switches from JRE 1.6 based on some searches in Stack Overflow).
The bare bone Android app works great when created. However, when I convert it to a Maven project, I start to get a ClassNotFoundException whenever I try to start the application. I tried updating the project, restarting Eclipse, checking all the libraries in the build path, cleaning up and rebuilding the project, restarting the emulator and reducing my pom.xml to a minimum.
What is the reason for this error? Is this some simple wrong configuration for Maven?
My logcat:
07-09 23:07:18.027: D/AndroidRuntime(958): Shutting down VM 07-09 23:07:18.027: W/dalvikvm(958): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 07-09 23:07:18.137: E/AndroidRuntime(958): FATAL EXCEPTION: main 07-09 23:07:18.137: E/AndroidRuntime(958): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myproject/com.example.myproject.MainActivity}: java.lang.ClassNotFoundException: com.example.myproject.MainActivity 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread.access$600(ActivityThread.java:123) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.os.Handler.dispatchMessage(Handler.java:99) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.os.Looper.loop(Looper.java:137) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread.main(ActivityThread.java:4424) 07-09 23:07:18.137: E/AndroidRuntime(958): at java.lang.reflect.Method.invokeNative(Native Method) 07-09 23:07:18.137: E/AndroidRuntime(958): at java.lang.reflect.Method.invoke(Method.java:511) 07-09 23:07:18.137: E/AndroidRuntime(958): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 07-09 23:07:18.137: E/AndroidRuntime(958): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 07-09 23:07:18.137: E/AndroidRuntime(958): at dalvik.system.NativeStart.main(Native Method) 07-09 23:07:18.137: E/AndroidRuntime(958): Caused by: java.lang.ClassNotFoundException: com.example.myactivity.MainActivity 07-09 23:07:18.137: E/AndroidRuntime(958): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 07-09 23:07:18.137: E/AndroidRuntime(958): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 07-09 23:07:18.137: E/AndroidRuntime(958): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.Instrumentation.newActivity(Instrumentation.java:1023) 07-09 23:07:18.137: E/AndroidRuntime(958): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) 07-09 23:07:18.137: E/AndroidRuntime(958): ... 11 more
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>4.1.1.4</version> <scope>provided</scope> </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
My MainActivity.java:
package com.example.myproject; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) {
Update: I found that trying to create Maven Clean and Maven will generate sources in pom.xml. However, installing Maven gives me an error:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] MainActivity.java:[12,33] package R does not exist [ERROR] MainActivity.java:[18,44] package R does not exist
I also added a few things (dependency and packaging), as well as a modified (1.6-> 1.7, 3.1-> 3.0) pom.xml file in this last board.
source share