[英]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.