34

I am having a problem with one of my apps and I was wondering if anyone could give me any insight into what maybe causing it.

I am getting a ClassNotFoundException, the important line below is

E/AndroidRuntime(21982): Caused by: java.lang.ClassNotFoundException: couk.doridori.goigo.customUI.GoBoardView in loader dalvik.system.PathClassLoader@446fc3d0

Now this app has been out for over a year and 2 days ago I had two seperate users contact me regarding this issue, one on a HTC wildfire (2.1) and one a Samsung Galaxy S (?). Now I cannot recreate this problem on my devices (2.2 and 1.6) or an emulator (2.1) and cannot really work out why this class cannot be found by the classloader. I have spent a while googling to no avail, and hopes someone has some pointers! It only seems to be when an activity is loaded which when the contentView is set, it tries to inflate a custom View called GoBoardView which extends the View class, this is just doing some simple canvas drawing and is not using any third party libs or any other classes that would have a packagename clash or anything.

Please help! Just in case its a build issue I am updating all my SDK and ADT through eclipse as it was building against 1.6 and using the old ADT, but I have no idea if this will help just thought worth a try. Any advice would be great thanks! (see below for EDIT)

E/AndroidRuntime(21982): java.lang.RuntimeException: Unable to start activity ComponentInfo{couk.doridori.goigoFull/couk.doridori.goigoFull.Board}: android.view.InflateException: Binary XML file line #14: Error inflating class couk.doridori.goigo.customUI.GoBoardView
E/AndroidRuntime(21982): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
E/AndroidRuntime(21982): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
E/AndroidRuntime(21982): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
E/AndroidRuntime(21982): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
E/AndroidRuntime(21982): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21982): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(21982): at android.app.ActivityThread.main(ActivityThread.java:4603)
E/AndroidRuntime(21982): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21982): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(21982): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(21982): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(21982): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21982): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class couk.doridori.goigo.customUI.GoBoardView
E/AndroidRuntime(21982): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
E/AndroidRuntime(21982): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime(21982): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
E/AndroidRuntime(21982): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
E/AndroidRuntime(21982): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime(21982): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(21982): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(21982): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
E/AndroidRuntime(21982): at android.app.Activity.setContentView(Activity.java:1629)
E/AndroidRuntime(21982): at couk.doridori.goigoFull.Board.onCreate(Board.java:31)
E/AndroidRuntime(21982): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(21982): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
E/AndroidRuntime(21982): ... 11 more
E/AndroidRuntime(21982): Caused by: java.lang.ClassNotFoundException: couk.doridori.goigo.customUI.GoBoardView in loader dalvik.system.PathClassLoader@446fc3d0
E/AndroidRuntime(21982): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime(21982): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(21982): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(21982): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
E/AndroidRuntime(21982): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
E/AndroidRuntime(21982): ... 22 more

EDIT

Ok, researching some of the links that users to have commented in reply to this question, it seems that the use of the wrong context for loading activities can cause this problem. I find this interesting becuase one of the two log reports i have been send has this exception preceeded by

W/ActivityManager( 1222): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { flg=0x20000 cmp=couk.doridori.goigoFull/.Games }

which is quite self explanatory - problem is i have no idea where this activity could be being started from where it uses a non activity context, so im a bit stumped, thinking it maye be some multitasking like quirk and its being brought back into the foreground of something . This can then apparently cause problems with the classLoader. If this was happening on a users phone i cant see why i cannot reproduce this (and most other users cannot either).

The other thing i found through the links which is interesting, is some people have encountered problems due to a "incorrect apk installation', which can be resolved by a reinstall, which i have asked the users who have had the problem to try (which does not make a difference). Also it seems once the problem is encountered (which is on first use) it will be persistent.

Dalmas
  • 26,409
  • 9
  • 67
  • 80
Dori
  • 18,283
  • 17
  • 74
  • 116
  • Do you have a Broadcast Receiver with the intent filter Intent.FLAG_ACTIVITY_NEW_TASK ? This could be the non-Activity context which could attempt to start one of your activities. – John J Smith Feb 15 '11 at 23:50

9 Answers9

34

I can't help but notice that your Activity name is couk.doridori.goigoFull.Board but your missing custom View class is couk.doridori.goigo.customUI.GoBoardView ... it looks like you might have two different packages (goigo vs goigoFull).

Are you by any chance doing clever things with library projects? You'll want to be really careful with fully-qualified classnames in code and in layout xml...

(If not please add some more information about your project setup and also paste your layout XML which the layoutinflater is choking on)

Reuben Scratton
  • 38,595
  • 9
  • 77
  • 86
  • ah fantastic, I had not noticed this - i will look into it and report back soon, thanks... – Dori Feb 16 '11 at 09:12
  • 1
    Yes this was the issue, I had overlooked this as i had a seperate layout file for small screens, in which I had used not updated the package name - what a stupid thing to have done :) I apparently have to wait 23 hours before awarding you the bounty, so will do. Again I should read the stack more thouroughly!! – Dori Feb 19 '11 at 20:37
  • Hi @Dori, glad to have been able to help. For what it's worth I have made very similar mistakes before now. It'd sure be helpful if the resource compiler would catch references to non-existent packages and raise them as errors... – Reuben Scratton Feb 19 '11 at 21:02
  • Thanks sir, I got the same problem , that was because of misspelling too , thnx a lot :) – Mahmoud Farahat Nov 21 '12 at 15:09
  • I have to say thanks, I also met this stupid thing. I didn't read exception carefully. – Sean Feb 28 '13 at 01:08
7

I was already discussing this problem here : Android: Unable to instantiate activity / ClassNotFoundException but we couldn't find a definite answer... However John J Smith's answer about the right use of Context is interesting.

Some people also resolved their problem on this thread and gives some ideas.

Hope this helps...

(By the way I'm happy to see another Go game programmer !)

Community
  • 1
  • 1
Dalmas
  • 26,409
  • 9
  • 67
  • 80
  • I'm not sure if this is the same issue as this exception appears to point to a specific line (14) in one of the XML files. – John J Smith Feb 02 '11 at 22:33
  • Yes you're right, I didn't see it... However there are some things in common : it's the same Exception, he is unable to reproduce the error, and it seems to happen randomly. – Dalmas Feb 02 '11 at 22:37
  • Hello, thanks for the links and answers - i have updated my post with some more info / thoughts at the bottom. :) – Dori Feb 06 '11 at 17:24
  • Also, the link you provided seems to be in app startup for all users, and other links followed seem to talk about restarting an app from notifications (of which my app has none), so similar but my app does start so i feel i cant rule out the SD card related errors. BTW what go stuff do you work on? – Dori Feb 06 '11 at 17:34
3

I added a custom layout and started seeing ClassNotFoundException messages after only on the signed application package but the development build was working just fine. I was using ProGuard and the new layout I added was not included in the "exclude" list in the ProGuard config. I included the custom layout in ProGuard exclude list and that fixed the issue for me.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Kiran
  • 31
  • 1
3

I encounter this problem sometimes when developing- ususally after changing package names. A quick clean of the project fixes the issue for me.

Dan
  • 39
  • 1
1

There's another thing that causes "ClassNotFoundException". Some time ago, the android project started using the libs directory for dependencies. If a jar is in the libs directory, it's on the classpath automatically so you don't have to add it in the project settings. However, jars in "libs" can't have sources attached (which is ridiculous). So if you want to attach a source, you move a jar from "libs" to "lib" and you add it to the classpath. You can attach the source. But I've seen several times that this triggers ClassNotFoundExceptions on my classes. Moving the jar back solves the problem.

Christine
  • 5,617
  • 4
  • 38
  • 61
1

I had the same issue. In the end the problem was just missing tabulations in the layout xml.

Before:

    <org.osmdroid.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent" 
    android:layout_height="0dip"
    tilesource="MapquestOSM" 
    android:layout_weight="1"
    />

Then with indentation the classNotFoundException never apeared again, and the map showed properly:

    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent" 
        android:layout_height="0dip"
        tilesource="MapquestOSM" 
        android:layout_weight="1"
    />
roky
  • 208
  • 2
  • 9
1

My experience may be that the android sdk was updated and the link to the support library needed to be refreshed. Just go to project settings > android and point to the support library again.

Yaojin
  • 341
  • 2
  • 6
1

For me the Problem was one little Caps-Fault. I looked up my code for hours where everything was all right. Some time I looked into my .xml-Files then - and there it was:

In the java-Files I used a ViewPager and in one nasty little piece of the xml I lost my caps and typed viewPager by mistake. Obvious, that this one was not able to be found...

Jochen Birkle
  • 335
  • 4
  • 14
0

this is due to the new version of eclipse ... remove all external dependencies from buildpath and add it again using project->properties->builspath->libraries tab. Now add back all dependency library and select all the components by clicking against them on order and project tab on project->properties->builspath- . this will work fine !

rana
  • 1,824
  • 3
  • 21
  • 36