gpt4 book ai didi

java - 为什么我会得到 ClassCastException?

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:51 25 4
gpt4 key购买 nike

我在运行这个简单的应用程序时遇到了 ClassCastException

我是第一次尝试使用 AlarmManager

public class AlarmReciever extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();

}
}

}

这是我的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tcs.mine"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AlarmReciever"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver>
</application>
</manifest>

我做错了什么?

最佳答案

AlarmReceiver 不是 Activity 但声明为一个。查看 BroadcastReceiver 上的文档和 how to declare them in the manifest file .也许你想查看 this tutorial

关于java - 为什么我会得到 ClassCastException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6015325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com