Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFoundException for a ContentProvider

Tags:

android

I have a ContentProvider class and is declared in AndroidMenifest.xml like this:

<provider android:name=".MediaSearchProvider"
    android:authorities="org.iii.romulus.meridian.mediasearch">
    <path-permission android:path="/search_suggest_query"
        android:readPermission="android.permission.GLOBAL_SEARCH" />
</provider>

It works well on most devices, but the Market tells me some users are suffering error with it. The stack trace is:

java.lang.RuntimeException: Unable to get provider org.iii.romulus.meridian.MediaSearchProvider: java.lang.ClassNotFoundException: org.iii.romulus.meridian.MediaSearchProvider in loader dalvik.system.PathClassLoader[/mnt/asec/org.iii.romulus.meridian-1/pkg.apk]
at android.app.ActivityThread.installProvider(ActivityThread.java:4509)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4281)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4237)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: org.iii.romulus.meridian.MediaSearchProvider in loader dalvik.system.PathClassLoader[/mnt/asec/org.iii.romulus.meridian-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.ActivityThread.installProvider(ActivityThread.java:4494)
... 12 more

I have totally no idea about what's up and I can't reproduce it on any of my phones. I also tried clean and build, but the report still comes up. Anyone can help? Thanks!

like image 625
Romulus Urakagi Ts'ai Avatar asked Jun 10 '11 07:06

Romulus Urakagi Ts'ai


3 Answers

The answers regarding proguard are incorrect. This would cause an easily reproducible error on every phone, every time, because the ContentProvider class would be completely missing. The developer clearly states that they cannot reproduce the error, meaning that the ContentProvider class is present but for some reason is not being found on one of their user's phones.

I have the same crash reported in the market for my app. The stack traces look identical, and the error is occurring at installProvider. I have about 15 test phones in my office and none of them can reproduce this problem. Any other ideas would be appreciated.

Fully qualified names in the manifest are only necessary if your java package names are not the same as your android package name. If a fully qualified name is not specified, the OS will automatically prepend the android package name to the class name specified in the manifest.

like image 88
OldSchool4664 Avatar answered Oct 13 '22 10:10

OldSchool4664


Ensure twice that you have correct qualified class name specified in AndroidManifest.xml, it must read something like this:

<provider
    android:authorities="org.iii.romulus.meridian.mediasearch"
    android:name="org.iii.romulus.meridian.MediaSearchProvider">
</provider>

Notice that @name is fully qualified.

like image 45
esteewhy Avatar answered Oct 13 '22 11:10

esteewhy


This sounds similar to an issue I had that was caused by an issue with the ClassLoader, see here: Bizarre behaviour when using Apache Commons lib in Android

This bug discusses an error relating to the class loader failing sometimes. The fix for me was to add this line:

Thread.currentThread().setContextClassLoader(this.getClassLoader());

in the constructor of the class that was calling the code that was failing.

like image 31
Jarrod Smith Avatar answered Oct 13 '22 09:10

Jarrod Smith