Unable to instantiate receiver , java.lang.ClassCastException
<pre><code>Problem: AutoStart On Boot Up causing classcastexception.. 

I am doing Location based application , I want to run the app whenever the phone bootup,So that my app will be running continuously, I just want to start the service as soon as the phone loads all the service.
</code></pre>

<p>I have wrote broadcast receiver method and in mainfest xml even set the receiver and permission 
    I am writing the following code but I am getting runtime error, I even tried to remove the activity and run but its causing the error . please suggest me some solution.</p>

<p><strong>MainFest.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.omkar_gpslocation"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" /&gt;

    &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.BATTERY_STATS" /&gt;
    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
       &lt;activity
            android:name="com.example.omkar_gpslocation.MainActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name="com.example.omkar_gpslocation.Activity_Settings"
            android:label="@string/title_activity_activity__settings" &gt;
        &lt;/activity&gt; 


&lt;receiver android:enabled="true" android:name="com.example.omkar_gpslocation.MainActivity"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED"&gt;

        &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
                &lt;category android:name="android.intent.category.DEFAULT" /&gt;
        &lt;/intent-filter&gt;
&lt;/receiver&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p><strong>MainActivity</strong></p>

<pre><code>private BroadcastReceiver MyReceiver= new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent serviceIntent = new Intent("com.example.omkar_gpslocation");
        context.startService(serviceIntent); 

    }
};
</code></pre>

<p><strong>Logcat:</strong></p>

<pre><code>02-04 13:21:08.462: E/AndroidRuntime(503): FATAL EXCEPTION: main
02-04 13:21:08.462: E/AndroidRuntime(503): java.lang.RuntimeException: Unable to instantiate receiver com.example.omkar_gpslocation.MainActivity: java.lang.ClassCastException: com.example.omkar_gpslocation.MainActivity
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:1873)
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.app.ActivityThread.access$2400(ActivityThread.java:155)
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1049)
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.os.Handler.dispatchMessage(Handler.java:130)
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.os.Looper.loop(SourceFile:351)
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.app.ActivityThread.main(ActivityThread.java:3820)
02-04 13:21:08.462: E/AndroidRuntime(503):  at java.lang.reflect.Method.invokeNative(Native Method)
02-04 13:21:08.462: E/AndroidRuntime(503):  at java.lang.reflect.Method.invoke(Method.java:538)
02-04 13:21:08.462: E/AndroidRuntime(503):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
02-04 13:21:08.462: E/AndroidRuntime(503):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
02-04 13:21:08.462: E/AndroidRuntime(503):  at dalvik.system.NativeStart.main(Native Method)
02-04 13:21:08.462: E/AndroidRuntime(503): Caused by: java.lang.ClassCastException: com.example.omkar_gpslocation.MainActivity
02-04 13:21:08.462: E/AndroidRuntime(503):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:1864)
02-04 13:21:08.462: E/AndroidRuntime(503):  ... 10 more
</code></pre>
