NullPointerException when using BroadcastReceiver
<p>I had an error message on the android screen. Here is the Logcat -</p>

<pre><code>02-08 09:33:42.471: E/AndroidRuntime(11592): java.lang.RuntimeException: Unable to start receiver something.MainActivity$CancelReceiver: java.lang.NullPointerException
</code></pre>

<p>Why is program working correctly after the error log? (Program is not killed)
when it throws broadcast first time, this error appears.</p>

<p>This is part of my code</p>

<pre><code>public static class CancelReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intents) {

            intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String OKorNOT = intents.getExtras().getString("OKorNOT");
            String str = intents.getExtras().getString("something");

            if(OKorNOT.equals("OK")){
                //OKの場合

                tv2.setText(str);
                //this line may throws error.tv means TextView object findview already.
            }else if(OKorNOT.equals("NOT")){
                //NOTの場合
                tv.setText("yeah");//this line also throws error
                pushB.setText("NO!");   
                tv2.setText("");
            }
</code></pre>

<p>what is wrong?</p>

<p>edited.
this onReceive is in static class.</p>

<p>and around oncreate about tv,tv2 is</p>

<pre><code>public class MainActivity extends Activity {

   static TextView tv;
   static TextView tv2;
   static Button pushB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

         pushB = (Button)findViewById(R.id.button2);
         tv = (TextView)findViewById(R.id.textView6);
         tv2 = (TextView)findViewById(R.id.textView7);
}
}
</code></pre>

<p>i did defined object in onCreate.</p>
