开发者

Why do I get a ClassCastException?

I am getting a ClassCastException on running this simple application.

I'm trying to use the AlarmManager for the first time.

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();

        }
     }

    }

this is my manisfest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tcs.mine"
      android:ver开发者_如何学JAVAsionCode="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> 

What am I doing wrong?


AlarmReceiver is not an Activity but declared as one. Check the documentation on BroadcastReceiver and how to declare them in the manifest file. Maybe you want to check this tutorial


The package statement is missing at the top of your java class.

Besides, check how the AlarmReceiver is spelled throughout your .java and .xml files. Somewhere is called AlarmReciever.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜