1

I'm developing an Android Wear extension to an existing app. While working on Android Studio I'm getting the following every time I'm running the wear module AFTER I run the main app, and the wear app crashes on start:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.mobile.activities.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.mobile-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mobile-2/lib/x86, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
            at android.app.ActivityThread.-wrap11(ActivityThread.java) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:148) 
            at android.app.ActivityThread.main(ActivityThread.java:5422)

The only solution I found for this is File > Invalidate Caches/Restart and then Build > Clean project. After that I can run the wear module (until the next main run).

This makes my work very slow. Can someone help me here? 

Matthew Woo
  • 1,288
  • 15
  • 28
AsafK
  • 2,425
  • 3
  • 32
  • 38
  • Stop your project and rebuild your project then run it again. I think that's maybe because you add MainActivity class after run your project and instant run cant do the job correctly. – Hossein Rashno Aug 03 '16 at 12:29
  • @HosseinRashno MainActivity is the wear app launcher activity. it was added when i just created the app. the problem keeps happening though. – AsafK Aug 03 '16 at 12:33
  • Can you show all the Gradle files, and how your project is structured? – OneCricketeer Aug 03 '16 at 12:56

1 Answers1

0

ClassNotFoundException was thrown when an application tries to load in a class through its string name using:

As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "optional exception that was raised while loading the class" that may be provided at construction time and accessed via the getException() method is now known as the cause, and may be accessed via the getCause() method, as well as the aforementioned "legacy method."

Found this SO related ticket, issue was resolved by doing steps below:

  • Right click on your project and select Properties.
  • Select Java Build Path from the menu on the left.
  • Select the Order and Export tab.
  • From the list make sure the libraries or external jars you added to your project are checked.
  • Finally, clean your project & run.

You may also check this SO ticket: Android Activity ClassNotFoundException - tried everything

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30