java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.cal/com.test.cal.CalculatorActivity}: java.lang.NullPointerException
<p>Hi. I tried to create a calculator app for Android. Tried to code to show two buttons such that clicking on one of them displays it in a text box.</p>

<p>The code is:</p>

<pre><code>package com.test.cal;

android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CalculatorActivity extends Activity implements OnClickListener {
    EditText ans;
    Button b1,b2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        ans = (EditText) findViewById(R.id.ans);
        b1=(Button) findViewById(R.id.one);
        b2=(Button) findViewById(R.id.two);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getId())
        {
        case R.id.one:
                ans.setText(1);
            break;
        case R.id.two:
                ans.setText(2);
            break;
        default:Toast.makeText(this, "fuckoff", 1000);
            break;  
        }
     }
   }
</code></pre>

<p>Clicking on the null point exception goes to the:</p>

<pre><code>b2=(Button) findViewById(R.id.two); 
</code></pre>

<p>line. Please help. I am a beginner. Searched stack overflow, but didn't understand the few answers related to it.</p>
