2

I receive a crash report from my production app, which tells me that there is an NoClassDefFound Exception on one of my activity.

The exception is thrown on this line:

final Intent i = new Intent(MainActivity.this, SomeActivity.class);

Where it claims that "SomeActivity" class is not found.

There is only one instance reported out of thousands of users. (On a Samsung Note Mini) Which means it shouldn't be a compilation or wrong lib included issue.

Is there any clues for me to continue my investigation?

p/s: The activity is definitely defined in manifest. Else it won't even works on other user's phones.

Stack:

java.lang.NoClassDefFoundError: com.sensored.SomeActivity
at com.sensored.MainActivity$2.onItemClicked(MainActivity.java:920)
at com.sensored.adapter.SomeListAdapter$2.onClick(SomeListAdapter.java:115)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3697)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Calvin
  • 3,302
  • 2
  • 32
  • 41
  • This might help you : http://stackoverflow.com/questions/4820554/android-unable-to-instantiate-activity-classnotfoundexception – The Dark Knight Jun 11 '13 at 09:44
  • 1
    Post stack trace for the error. Also look ate here : http://stackoverflow.com/questions/4880489/android-classnotfoundexception – The Dark Knight Jun 11 '13 at 09:46
  • @Sam It is just inside a regular onClickListener. The next line after this is startActivity(i) – Calvin Jun 11 '13 at 09:47
  • Android's internal bug? – Pointer Null Jun 11 '13 at 09:47
  • @Calvin have you mention SomeActivity in manifest.? – Sagar Maiyad Jun 11 '13 at 10:04
  • Post the full stacktrace. There is a corresponding `cause`. NoClassDefFoundError means that there was an error when creating the class. – John Vint Jun 11 '13 at 10:43
  • @JohnVint That's the stack I have from bugsense. It is from an user's phone. I can't reproduce on all my devices. – Calvin Jun 11 '13 at 11:00
  • Hm, well can you post source for SomeActivity? We may be able to infer the error. Specifically useful code is the `static{` block and any inline static fields. – John Vint Jun 11 '13 at 11:03
  • The error you are seeing is usually one of two things. 1. ClassNotFound which I have a hard time believing. 2. There was an error when the class was initialized for instance, the static block throw an uncaught exception or creating static fields threw an uncaught exception – John Vint Jun 11 '13 at 11:04

1 Answers1

0

1) Keep all activities under same package[say com.compname.proj.views].

2) Ensure in manifest, package attribute is set to the above package[i.e com.compname.proj.views].

3) In manifest, under all activity tag, make sure android:name attribute has values matching to below pattern:

        android:name=".<your activity class name>"

Ex: android:name=".SomeActivity"

My point is not to use package name + activity class name for manifest activity declaration.

Chandan Adiga
  • 576
  • 4
  • 14
  • Yes. That's what exactly I did. (If I didn't it won't work on other user's phones right?) – Calvin Jun 11 '13 at 17:30
  • Need not be. Usually Android system prefix project package name to activity name. In that case, if you have declared package name + activity name, under activity tag, then overall class path will not be found by system! [You could try cleaning the project, rebuild and test new build on the device in which the crash was reported.] – Chandan Adiga Jun 12 '13 at 07:04
  • The phone that report this issue is somewhere in this world which I has no access to. I need to be able to reproduce it. I try your theory with full path or without, it has no differences. Won't crash. – Calvin Jun 13 '13 at 01:58