0

I'm having a problem regarding an Android app. Here's the error message:

06-29 16:07:28.263: E/AndroidRuntime(196): Uncaught handler: thread main exiting due to uncaught exception
06-29 16:07:28.463: E/AndroidRuntime(196): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidcalc/com.calc.AndroidCalc}: java.lang.ClassNotFoundException: com.calc.AndroidCalc in loader dalvik.system.PathClassLoader@44c067c8
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.os.Looper.loop(Looper.java:123)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread.main(ActivityThread.java:4363)
06-29 16:07:28.463: E/AndroidRuntime(196):  at java.lang.reflect.Method.invokeNative(Native Method)
06-29 16:07:28.463: E/AndroidRuntime(196):  at java.lang.reflect.Method.invoke(Method.java:521)
06-29 16:07:28.463: E/AndroidRuntime(196):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-29 16:07:28.463: E/AndroidRuntime(196):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-29 16:07:28.463: E/AndroidRuntime(196):  at dalvik.system.NativeStart.main(Native Method)
06-29 16:07:28.463: E/AndroidRuntime(196): Caused by: java.lang.ClassNotFoundException: com.calc.AndroidCalc in loader dalvik.system.PathClassLoader@44c067c8
06-29 16:07:28.463: E/AndroidRuntime(196):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-29 16:07:28.463: E/AndroidRuntime(196):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-29 16:07:28.463: E/AndroidRuntime(196):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-29 16:07:28.463: E/AndroidRuntime(196):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
06-29 16:07:28.463: E/AndroidRuntime(196):  ... 11 more

I've checked Google for some help and found a couple other threads on SO about this, but none of those seem to match my case. Here's what happened:

I have an app I started writing about a year or so ago. For a while, I shelved it despite it being incomplete because I had other things going on. I just came back to it today after about 6 months of inactivity to try to implement a UI for tablets (currently the Tablet UI is borrowing from the smaller screen UI which is super ugly). Here's what I did:

1) I created a folder layout-large to store the new UI elements, and I CTRL-C CTRL-V'd in the UI elements from the smaller layout folders as a base to work with.

2) I realized my tablet was actually classified extra large, so I repeated step 1 except with layout-xlarge.

3) I modified some of the UI dressings in layout-xlarge (text sizes and element sizes only, did not touch any code).

4) I noticed that I had not installed the required SDKs to emulate my tablet (I only had up to 4.0.3 and needed 4.1.2), so I updated my SDKs through the SDK Manager.

5) After updating the SDKs, I created the Tablet VM.

6) I was told Eclipse needed to update a bunch of things, so I did that.

7) After updating Eclipse, I was told I needed to go back into the SDK manager and update some more things (specifically something called Build-tools), so I did that.

8) I ran the program on my Tablet VM and got the above error.

9) I ran the program on my phone VM (which worked under the previous version) and got the above error.

Somehow in proceeding with the above steps, without touching a single line of code or adding any new Activity elements (except for additional UIs), I managed to bugger up my application to the point that it will not run. I have tried the following things already:

1) I have checked my Android Manifest. The only thing in it is the single sole Activity application that is supposed to be there.

2) I have done a Project Clean.

3) A previous thread I read suggested I delete the "bin" and "gen" directories and rebuild those. I did that.

None of these 3 things have worked. Does anyone have any further suggestions? Thanks.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
Ertai87
  • 1,156
  • 1
  • 15
  • 26

1 Answers1

1

It seems that you have some problem with packages. I see that the application package is declared as com.androidcalc, but the class you're trying to instantiate is com.calc.AndroidCalc. So I think there's a mismatch between the actual class name and the declared name. This means that you should:

  • Check the package name in the project and change it to com.androidcalc or com.calc.
  • Check the AndroidManifest.xml and set the package to the exact same thing there, both in the application and the activity declarations.
Malcolm
  • 41,014
  • 11
  • 68
  • 91
  • Thanks. Tried that. Now the package is com.calc.androidcalc (it's written like that everywhere in the project, as best I can tell) and the Activity is com.calc.AndroidCalc. It's still not running, and as best as I can tell the error message is the same modulo the change s/com.androidcalc/com.calc.androidcalc/g. – Ertai87 Jun 29 '13 at 08:43
  • @Ertai87 It is not running because the package is still not the same. You declared the package as `com.calc.androidcalc` and the activity is in the package `com.calc`. – Malcolm Jun 29 '13 at 19:45
  • Sorry about that. Not quite used to this package thing; this is still my first app. Anyway, I fixed that, but still getting the same error (this time com.calc/com.calc.AndroidCalc). Did a Project Clean as well, just in case, but no luck. Anything else I should check? Just for fun I also tried changing the target SDK build to most recent (17 from 7) in case that would help, but that didn't help either. My AVDs are on SDK 7 and SDK 16, because those are the 2 IRL devices I own. – Ertai87 Jun 30 '13 at 04:26
  • @Ertai87 Does the activity have a declaration at the top `package com.calc`? Also check other questions like [this one](http://stackoverflow.com/questions/7460095/unable-to-instantiate-activity-componentinfo?rq=1). – Malcolm Jun 30 '13 at 12:47
  • Alright, so as per that thread, I deleted all my libraries except the Android 2.1 library, then re-added the v4.support library (to use Fragments in SDK 7) and something called JRE System Library (which I don't really understand but it looked useful), and now it seems to run under SDK7 (my phone emulator). It still won't run on SDK 16, though, which is my target, although the error message is different now. Any idea why a project might run fine on SDK 7 but crash on SDK16? Apparently it's yelling about a NullPointerException, but it runs fine on SDK7, which is making me wonder. – Ertai87 Jul 01 '13 at 03:20
  • Nevermind. I'm actually just stupid. Turns out the problem was I didn't instantiate layout-xlarge-land, and the tablet emulator was in landscape by default. I had a bunch of extra code which does setup for extra elements that only appear in landscape, but it wasn't finding the landscape UI so it was Nulling those values and throwing NullPointerExceptions at me. After adding layout-xlarge-land it works fine =D Thanks for all the help. – Ertai87 Jul 01 '13 at 03:42