繁体   English   中英

BroadcastReceiver java.lang.ClassNotFoundException

[英]BroadcastReceiver java.lang.ClassNotFoundException

我尝试在电话启动时显示一条简单的吐司消息。 我浪费了几乎一天的时间来弄清楚为什么我的代码不起作用。

这是完整的错误:

Unable to instantiate receiver com.debug.receivebootcomplete.debug.BroadcastReceiverClass: java.lang.ClassNotFoundException: com.debug.receivebootcomplete.debug.BroadcastReceiverClass

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.debug.receivebootcomplete.debug">
    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name">
        <receiver android:name=".BroadcastReceiverClass" android:exported="true">
            <intent-filter> 
                <action android:name="android.intent.action.BOOT_COMPLETED" /> 
            </intent-filter> 
        </receiver>
</application>
</manifest>

而我的班级:

namespace Debug
{
    class BroadcastReceiverClass:BroadcastReceiver
    {
        public override void OnReceive (Context context, Intent intent)
        {
            Toast.MakeText (context,"Work",ToastLength.Short).Show ();
        }
    }
}

在模拟器调试中,应用程序抛出java.lang.ClassNotFoundException并在重新启动应用程序时崩溃。

先感谢您!

谢谢@Talha!

我的错误是由intent-filter标记生成的。 我不知道为什么,因为在我看到的每个主题中,每个人都在清单文件中使用了该标记。

        <intent-filter> 
            <action android:name="android.intent.action.BOOT_COMPLETED" /> 
        </intent-filter>

所以我将其删除并添加[BroadcastReceiver] [IntentFilter(new[] {Intent.ActionBootCompleted})]

到BroadcastReceiver类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM