Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Broadcast Receiver Error: Class not found exception
    text
    copied!<p>I have a Broadcast receiver setup so that a pop-up message is displayed to the user after each upgrade of my app, or if this is the first time the package is installed. I tested this on my Droid running Android 2.2 both as a fresh install and after upgrading my app, as well in the Emulator running 1.5 and 1.6, and I see everything run fine.</p> <p>However, I received an error report from a user that lists the following exception:</p> <pre><code>java.lang.RuntimeException: Unable to instantiate receiver com.name.pkg.FirstRunBroadcastReceiver: java.lang.ClassNotFoundException: com.name.pkg.app_name.FirstRunBroadcastReceiver in loader dalvik.system.PathClassLoader[/data/app/com.name.pkg.app_name.apk] at android.app.ActivityThread.handleReceiver(ActivityThread.java:2789) at android.app.ActivityThread.access$3200(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083) 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:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: com.name.pkg.app_name.FirstRunBroadcastReceiver in loader dalvik.system.PathClassLoader[/data/app/com.name.pkg.app_name.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.handleReceiver(ActivityThread.java:2780) ... 10 more </code></pre> <p>Can someone tell me why one of my users received this exception?</p> <p>In my Manifest file, I have things setup like this:</p> <pre><code>&lt;receiver android:name=".FirstRunBroadcastReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PACKAGE_REPLACE"/&gt; &lt;data android:scheme="package" android:path="com.name.pkg.app_name"&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>The class FirstRunBroadcastReceiver is setup like this:</p> <pre><code>package com.name.pkg.app_name; public class FirstRunBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Contenxt context, Intent intent) { Uri uri = intent.getData(); if( uri.toString().compareTo("package:com.name.pkg.app_name") == 0 ) { //set shared prefs data to determine if start-up message should be shown } } } </code></pre> <p>Upon a first time install, the default value for the shared prefs is set so that the pop-up message will be displayed, but I wouldn't think that would have anything to do with this exception.</p> <p>I tested it again, and I don't receive an exception. Thanks for any help you can provide.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload