Background music for a call
<p>I am doing an app which plays music in background for call, My app having a main activity ,A broadcast listener and a service. </p>

<p>The code for the broadcast listener is</p>

<pre><code>public class CallBrdcstListener extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    PhoneStateDisplay phoneListener=new PhoneStateDisplay();
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

    telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
}
</code></pre>

<p>The phone state listener is </p>

<pre><code>   public class PhoneStateDisplay extends PhoneStateListener{

 private Context context;
public void onCallStateChanged(int state,String incomingNumber){
    switch(state)
    {
       case TelephonyManager.CALL_STATE_IDLE:
            Log.d("DEBUG", "IDLE");
            break;
       case TelephonyManager.CALL_STATE_OFFHOOK:

            Log.d("DEBUG", "OFFHOOK");
             System.out.println("Calling Intent");
            Intent musicIntent = new Intent(context,MusicService.class); 
            context.startService(musicIntent);  

            break;

       case TelephonyManager.CALL_STATE_RINGING:
           Log.d("DEBUG", "RINGING");
           break;
    }
}   
}
</code></pre>

<p>It showing error in intent cration part...can anybody tell me what is the mistake</p>

<p>The logcat output is</p>

<pre><code>01-18 15:45:57.250: I/System.out(2822): Calling Intent
01-18 15:46:30.453: E/AndroidRuntime(2857): FATAL EXCEPTION: main
01-18 15:46:30.453: E/AndroidRuntime(2857): java.lang.NullPointerException
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.content.ComponentName.&lt;init&gt;(ComponentName.java:75)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.content.Intent.&lt;init&gt;(Intent.java:2823)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at com.example.backgroundmusicplay.PhoneStateDisplay.onCallStateChanged(PhoneStateDisplay.java:22)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:319)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.os.Looper.loop(Looper.java:130)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at android.app.ActivityThread.main(ActivityThread.java:3687)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at java.lang.reflect.Method.invokeNative(Native Method)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at java.lang.reflect.Method.invoke(Method.java:507)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-18 15:46:30.453: E/AndroidRuntime(2857):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
 01-18 15:46:30.453: E/AndroidRuntime(2857):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>
