问题
I'm trying to implement maven into an existing android project.
I've done so through the context menu > Configure
> Convert to Maven project
. And everything seems okay, no warnings or errors.
But when I try to run the app (just like before) I get:
12-31 10:16:57.423: E/AndroidRuntime(14242): java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{xxx/xxx.MainActivity}:
java.lang.ClassNotFoundException: xxx.MainActivity
I've followd all the instructions on implementing m2e and everything looks like it should work.
If I don't convert the project to a maven project, the app runs fine.
Any suggestions where I'm failing?
This is what my pom.xml looks like: http://pastebin.com/ByXA0BP4
回答1:
This took me ages to resolve and it was the OP's answer which guided me.
After enabling Maven for the project, you need to disable "Allow output folders for source folders"
Steps:
Project Properties
-> Java Build Path
-> Source Tab
-> Untick "Allow output folders for source folders"
-> Click OK
I also noticed that I got the following message in the console, which led me down a rabbit warren of false leads:
trouble writing output: already prepared
回答2:
I figured it out myself.
After converting the project to a maven project, right click on the 'src' folder and chose Build path
> Use as Source Folder
Now the project runs fine
回答3:
ClassNotFoundException is simple, the respective jar is not there in class path.I checked your pom.xml, but i was unable to relate any dependency that could have xxx.MainActivity. So just ensure that respective jar is there as dependency artifact that contains MainActivity. If it still would not work, try copy pasting the jar manually into deployment\lib folder and it should work. Another option could be to debug your current CLASSPATH location and see if your jars are there or not.
Also by default Maven probably would not update dependencies. You have to right click->Maven-> Update Project to download any newly added dependencies in your pom.xml. There might be an error downloading dependency for that you have you to find the right repository or download the jar locally and install it as local artifact.
Thanks
回答4:
You may check if the virtual or real device where you are testing the app is actually compatible with the target Api of the project. Change it to the proper one and check again.
来源:https://stackoverflow.com/questions/20855072/java-lang-classnotfoundexception-android-eclipse-maven-osx