Android - global variable java.lang.NullPointerException
<p>I have 2 methods which use same 2 buttons + 1 TextView. Something like this:</p>

<pre><code>public void startChange(View v) {
    final Button start = (Button) findViewById(R.id.start);
    final Button restart = (Button) findViewById(R.id.restart);
    final TextView check = (TextView) findViewById(R.id.check);
    //TO-DO part - Sets check to something based on buttons TagID
}

public void restartChange (View v) {
    final Button start = (Button) findViewById(R.id.start);
    final Button restart = (Button) findViewById(R.id.restart);
    final TextView check = (TextView) findViewById(R.id.check);
    //TO-DO part - Restars everything to basic position
}
</code></pre>

<p>everything worked fine.. But as soon as I made this buttons and textview global variable I got java.lang.NullPointerException.
Any idea how to fix it?</p>

<p><strong>Edit:</strong>
Problem solved.
Only think you have to do is to define buttons and textview in onCreate method not in global definition..</p>

<p>Example:</p>

<pre><code>public class Example extends Activity {
    Button start;
    Button restart;
    TextView t;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        start = (Button) findViewById(R.id.start);
        restart = (Button) findViewById(R.id.restart);
       check = (TextView) findViewById(R.id.check);
    }
}
</code></pre>
