Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imported project throws java.lang.ClassNotFoundException

So I imported an existing project to eclipse and I have a lot of trouble making it work. The project came with three other library projects:

  • google_play_services-lib

  • CaptureActivity

  • PortraitQR

As soon as I imported the project, I went under 'Java Build Path' and added paths for needed jars: enter image description here

After I successfully added the needed jars, I went on to the libraries. I imported all three needed libraries (that I was given along with the project) and it all went well: enter image description here

After that I also made sure private libraries are checked under the export tab: enter image description here

After I was done importing the project I tried to run it but it crashed instantly. This is the logcat file:

07-17 17:33:36.543: E/AndroidRuntime(25965): FATAL EXCEPTION: main
07-17 17:33:36.543: E/AndroidRuntime(25965): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{si.dvanadva.evanturist/si.dvanadva.evanturist.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "si.dvanadva.evanturist.MainActivity" on path: /data/app/si.dvanadva.evanturist-1.apk
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.os.Looper.loop(Looper.java:137)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at java.lang.reflect.Method.invokeNative(Native Method)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at java.lang.reflect.Method.invoke(Method.java:511)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at dalvik.system.NativeStart.main(Native Method)
07-17 17:33:36.543: E/AndroidRuntime(25965): Caused by: java.lang.ClassNotFoundException: Didn't find class "si.dvanadva.evanturist.MainActivity" on path: /data/app/si.dvanadva.evanturist-1.apk
07-17 17:33:36.543: E/AndroidRuntime(25965):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-17 17:33:36.543: E/AndroidRuntime(25965):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-17 17:33:36.543: E/AndroidRuntime(25965):    ... 11 more

I can see from the logcat file that the problem is 'finding MainActivity class'

Solutions that I have tried so far:

  • Checked if MainActivity is correctly declared in the AndroidManifest file (it is)

  • Checked private libraries under the export tab

  • Deleted bin folder and cleaned project

  • I also tried declaring activities in the AndroidManifest file by not including the package name, like this: android:name=".activityname"

  • Deleted the previous version of the app from my phone and tried compiling again

  • Checked for si.dvanadva.evanturist-1.apk in workspace project but I can't find it (am I missing it?)

  • Did this to set JAVA_HOME but it doesn't work

  • Started a new android application project and copied files in there

Maybe I also tried something else but I forgot to mention it, I've been working on this for quite a while now and I'm running out of things to try. I'll greatly appreciate any kind of help!

like image 259
Guy Avatar asked Jul 07 '26 22:07

Guy


1 Answers

I've fairly certain I've seen things like this happen when I haven't imported the code into Eclipse, but have tried to run the library from its downloaded location e.g. for Google Play Game Services:

Import the TypeANumber and BaseGameUtils code from the Android samples into your workspace. To do this in Eclipse: Click File > Import > Android > Existing Android Code into Workspace. Browse to the directory where you downloaded TypeANumber on your development machine and click OK to import the files. Perform the same steps for BaseGameUtils.

(I got this from https://developers.google.com/games/services/android/quickstart)

Also ,although this is not an exact fit for your problem:

Google Player Game Service Error: Can't build the sample game

like image 94
IanB Avatar answered Jul 09 '26 11:07

IanB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!