0

I am getting Null Pointer Exception in button.setOnClickListener why i don't know. i just check all xml file and other stuff but still getting any one can please resolve my problem.

Thanks in Advance.

public class StartingPoint extends Activity implements View.OnClickListener{

Button bLearn_Basic_C_Programs;
Button bC_Programs;
Button bMoreApps;

String thepixelmakerWebSiteAddress ="";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c_programs_start);


    bLearn_Basic_C_Programs = (Button)findViewById(R.id.bLearn_Basic_C_Programs);
    bC_Programs             = (Button) findViewById(R.id.bC_Programs);
    bMoreApps               = (Button) findViewById(R.id.bMoreApps);



    Log.d("here", "first");
            // i getting exception here
    bLearn_Basic_C_Programs.setOnClickListener(this);
    Log.d("here", "second");
    bC_Programs.setOnClickListener(this);
    bMoreApps.setOnClickListener(this);


}

public void onClick(View view) {

      switch(view.getId()){

      case R.id.bLearn_Basic_C_Programs: 

          Intent intent1 = new Intent(StartingPoint.this, Learn_Basic_C_Programs_Start.class);
          this.startActivity(intent1);
           break;

      case R.id.bC_Programs:

          Intent intent2 = new Intent(StartingPoint.this, C_Programs_Start_1_50.class);
          this.startActivity(intent2);
          break;

      case R.id.bMoreApps:
          Intent intenMoreApps = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(thepixelmakerWebSiteAddress));
          startActivity(intenMoreApps);
          break;
      }
}

}

1
  • 2
    Are you sure that your c_programs_start layout includes R.id.bLearn_Basic_C_Programs ? Commented Apr 18, 2014 at 18:04

1 Answer 1

4

It seems that findViewById really isn't finding the button. My guess is that either, c_programs_start is incorrect or your id's are incorrect.

In the future, you should try to paste the xml as well for these sorts of questions.

Sign up to request clarification or add additional context in comments.

2 Comments

still getting same exception
sorry i resolve the problem thanks for your cooperation. ya you are right findViewById isn't finding the button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.