开发者

Error report java.lang.ClassNotFoundException

开发者 https://www.devze.com 2023-04-12 14:09 出处:网络
In the developer console I get some error reports about the following Exception: java.lang.RuntimeException: Unable to instantiate receiver com.cypressworks.changelogviewer.InstallReciever: java.lang

In the developer console I get some error reports about the following Exception:

java.lang.RuntimeException: Unable to instantiate receiver com.cypressworks.changelogviewer.InstallReciever: java.lang.ClassNotFoundException: com.cypressworks.changelogviewer.InstallReciever in loader dalvik.system.PathClassLoader[/mnt/asec/com.cypressworks.changelogviewer-1/pkg.apk]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1773)
at android.app.ActivityThread.access$2400(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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:845)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.cypressworks.changelogviewer.InstallReciever in loader dalvik.system.PathClassLoader[/mnt/asec/com.cypressworks.changelogviewer-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764)
... 10 more

A user added the message, that this error happend when he updated the app itself in the market.

I never experienced this Exception myself, although I have a guess about the cause. The receiver listens to android.intent.action.PACKAGE_REPLACE and android.intent.action.PACKAGE_ADDED. When the app itself is updated a broadcast is sent to the receiver, but at the time it should receive it, it is already deleted.

Does my guess sound reasonable and how to avoid this error?

Here's the manifest entry:

        <receiver
            android:name=".InstallReciever"
            android:exported="false"
            android:enabled="true">
            <intent-filter>
                <action
                    android:name="android.intent.action.PACKAGE_REPLACED" />
                <action
                    android:name="android.intent.action.PACKAGE_ADDED" />
                <data
                    android:scheme="package" />
            </intent-filter>
        </receiver>

Here's the code:

public class InstallReciever extends BroadcastReceiver {

    @Override
    public void onReceive(final Context c, final Intent intent) {
        final SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(c);

        //Checking some preferences...

        //Creating a notification

        final String ns = Context.NOTIFICATION_SERVICE;
        final NotificationManager mNotificationManager = (NotificationManager) c
                .getSystemService(ns);

        final int icon = R.drawable.icon;
        final CharSequence tickerText = c.getString(R.string.notification_text);
        final long when = System.currentTimeMillis();

        final Notification notification = new Notification(icon, tickerText,
                when);

        final CharSequence contentText = c.getString(R.string.app_name);

        final Intent notificationIntent = new Intent(c,
                ChangeListActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);

        final PendingIntent contentIntent = PendingIntent.getActivity(c, 0,
                notificationIntent, 0);

        notification.setLatestEventInfo(c, tickerText, contentText,
                contentIntent);

        mNotificationManager.notify(0, not开发者_如何学编程ification);
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号