1

我尝试在手机启动时显示简单的烤面包信息。 我浪费了将近一天的时间,试图找出为什么我的代码无法工作。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并在重启应用程序崩溃时在手机上。

预先感谢您!

+0

你在用'Xamarin'吗? – giannisf

+0

你在哪里打电话给这个班?我们可以看到那个代码吗? – Rafa

+0

看看这个:https://forums.xamarin.com/discussion/13614/how-do-i-update-my-activity-using-a-broadcastreceiver – Talha

回答

2

谢谢@Talha!

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

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

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

到广播接收器类。

相关问题