Why am I getting a ClassCastException?

I start ClassCastExceptionwhen I start this simple application.

I am trying to use AlarmManagerfor 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: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> 

What am I doing wrong?

+3
source share
2 answers

AlarmReceiveris not Activity, but declared as one. Check the documentation BroadcastReceiverand how to declare them in the manifest file . You might want to check out this tutorial.

+4
source

There is no package instruction at the top of your java class.

Also, check how AlarmReceiver is written in all .java and .xml files. Somewhere called AlarmReciever.

0
source

All Articles