I am trying to implement a java class that keeps football facts. it allows the user to click an image button in order to increment a value. a keep a different int value for each button, at when the user clicks on the image button, the counter is incremented and then showed on individual editTexts. I get a null point exception when the activity runs. can somebody why I get this null point exception at line 68?
package com.example.buttondemo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.EditText;
import android.app.Activity;
public class FootballFacts extends Activity implements OnClickListener {
ImageButton btnGoalBlue,btnGoalRed,btnFoulBlue,btnFoulRed,btnCornerBlue,btnCornerRed,btnYellowBlue,btnYellowRed,
btnRedBlue,btnRedRed, btnRestartValues;
EditText textGoalBlue,textGoalRed,textFoulBlue,textFoulRed,textYellowBlue,textYellowRed,textRedBlue,
textRedRed,textCornerBlue,textCornerRed;
int counterBlueGoal,counterRedGoal,counterCornerBlue,counterCornerRed,counterFoulBlue,counterFoulRed,counterYellowBlue,counterYellowRed,
counterRedBlue,counterRedRed= 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_football_facts);
//find the buttons in layout
btnGoalBlue = (ImageButton)findViewById(R.id.btnGoalBlue);
btnGoalRed = (ImageButton)findViewById(R.id.btnGoalRed);
btnFoulBlue = (ImageButton)findViewById(R.id.btnFoulBlue);
btnFoulRed = (ImageButton)findViewById(R.id.btnFoulRed);
btnCornerBlue = (ImageButton)findViewById(R.id.btnCornerBlue);
btnCornerRed = (ImageButton)findViewById(R.id.btnCornerRed);
btnYellowBlue = (ImageButton)findViewById(R.id.btnYellowBlue);
btnYellowRed = (ImageButton)findViewById(R.id.btnYellowRed);
btnRedBlue = (ImageButton)findViewById(R.id.btnRedBlue);
btnRedRed = (ImageButton)findViewById(R.id.btnRedRed);
btnRestartValues = (ImageButton)findViewById(R.id.btnResetFacts);
//textfields
textGoalBlue = (EditText)findViewById(R.id.editTextGoalBlue);
textGoalRed = (EditText)findViewById(R.id.editTextGoalRed);
textFoulBlue = (EditText)findViewById(R.id.editTextFoulBlue);
textFoulRed = (EditText)findViewById(R.id.editTextFoulRed);
textYellowBlue = (EditText)findViewById(R.id.editTextYellowBlue);
textYellowRed = (EditText)findViewById(R.id.editTextYellowRed);
textRedBlue = (EditText)findViewById(R.id.editTextRedBlue);
textRedRed = (EditText)findViewById(R.id.editTextRedRed);
textCornerBlue = (EditText)findViewById(R.id.editTextCornerBlue);
textCornerRed = (EditText)findViewById(R.id.editTextCornerRed);
//---set on click listeners on the buttons-----
btnGoalBlue.setOnClickListener(this);
btnGoalRed.setOnClickListener(this);
btnCornerBlue.setOnClickListener(this);
btnCornerRed.setOnClickListener(this);
btnFoulBlue.setOnClickListener(this);
btnFoulRed.setOnClickListener(this);
btnYellowBlue.setOnClickListener(this);
btnYellowRed.setOnClickListener(this);
btnRedBlue.setOnClickListener(this);
btnRedRed.setOnClickListener(this);
btnRestartValues.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == btnGoalBlue){
counterBlueGoal++;
textGoalBlue.setText(Integer.toString(counterBlueGoal));
}
if (v == btnGoalRed){
counterRedGoal++;
textGoalRed.setText(Integer.toString(counterRedGoal));
}
if (v == btnFoulBlue){
counterFoulBlue++;
textFoulBlue.setText(Integer.toString(counterFoulBlue));
}
if (v == btnFoulRed){
counterFoulRed++;
textFoulRed.setText(Integer.toString(counterFoulRed));
}
if (v == btnCornerBlue){
counterCornerBlue++;
textCornerBlue.setText(Integer.toString(counterCornerBlue));
}
if (v == btnCornerRed){
counterCornerRed++;
textCornerRed.setText(Integer.toString(counterCornerRed));
}
if (v == btnYellowBlue){
counterYellowBlue++;
textYellowBlue.setText(Integer.toString(counterYellowBlue));
}
if (v == btnYellowRed){
counterYellowRed++;
textYellowRed.setText(Integer.toString(counterYellowRed));
}
if (v == btnRedBlue){
counterRedBlue++;
textRedBlue.setText(Integer.toString(counterRedBlue));
}
if (v == btnRedRed){
counterRedRed++;
textRedRed.setText(Integer.toString(counterRedRed));
}
if (v == btnRestartValues){
counterBlueGoal = 0;
counterRedGoal = 0;
counterCornerBlue = 0;
counterCornerRed = 0;
counterYellowBlue = 0;
counterYellowRed = 0;
counterRedBlue = 0;
counterRedRed = 0;
counterFoulBlue = 0;
counterFoulRed = 0;
textGoalBlue.setText(Integer.toString(counterBlueGoal));
textGoalRed.setText(Integer.toString(counterRedGoal));
textYellowBlue.setText(Integer.toString(counterYellowBlue));
textYellowRed.setText(Integer.toString(counterYellowRed));
textRedBlue.setText(Integer.toString(counterRedBlue));
textRedRed.setText(Integer.toString(counterRedRed));
textCornerBlue.setText(Integer.toString(counterCornerBlue));
textCornerRed.setText(Integer.toString(counterCornerRed));
textFoulBlue.setText(Integer.toString(counterFoulBlue));
textFoulRed.setText(Integer.toString(counterFoulRed));
}
}
}
logcat file
-03 14:39:10.959: D/AndroidRuntime(7371): Shutting down VM
02-03 14:39:10.959: W/dalvikvm(7371): threadid=1: thread exiting with uncaught exception (group=0x415e6ce0)
02-03 14:39:10.969: E/AndroidRuntime(7371): FATAL EXCEPTION: main
02-03 14:39:10.969: E/AndroidRuntime(7371): Process: com.example.buttondemo, PID: 7371
02-03 14:39:10.969: E/AndroidRuntime(7371): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.buttondemo/com.example.buttondemo.FootballFacts}: java.lang.NullPointerException
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.os.Handler.dispatchMessage(Handler.java:102)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.os.Looper.loop(Looper.java:136)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread.main(ActivityThread.java:5146)
02-03 14:39:10.969: E/AndroidRuntime(7371): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 14:39:10.969: E/AndroidRuntime(7371): at java.lang.reflect.Method.invoke(Method.java:515)
02-03 14:39:10.969: E/AndroidRuntime(7371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
02-03 14:39:10.969: E/AndroidRuntime(7371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-03 14:39:10.969: E/AndroidRuntime(7371): at dalvik.system.NativeStart.main(Native Method)
02-03 14:39:10.969: E/AndroidRuntime(7371): Caused by: java.lang.NullPointerException
02-03 14:39:10.969: E/AndroidRuntime(7371): at com.example.buttondemo.FootballFacts.onCreate(FootballFacts.java:68)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.Activity.performCreate(Activity.java:5231)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-03 14:39:10.969: E/AndroidRuntime(7371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
02-03 14:39:10.969: E/AndroidRuntime(7371): ... 11 more