在Txt_EarnedPoint.getText()行中它抛出Nullpointer异常为什么? Txt_EarnedPoint是一个textview。如果我删除该行,每个想法都可以。 Plz帮帮我......
public class MainActivity extends ActionBarActivity implements
android.view.View.OnClickListener {
private TextView Txt_EarnedPoint;
private Button saveButton;
private Button DisableBtn;
private Button selectbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView Txt_EarnedPoint=(TextView ) findViewById(R.id.textView1);
public void GetImageId(int Imageid) {
else if (count == 1
&& CheckBtnText == selectbutton.getText().toString()) {
selectbutton.setBackgroundResource(selectAptImage);
selectbutton.setEnabled(false);
count = 0;
IncCounter += 1;
saveButton.setText("0");
selectbutton.setText("0");
--error part----------->Txt_EarnedPoint.getText();
if (IncCounter == 6) {
AlertDialog d = new AlertDialog.Builder(this)
.setTitle("Completed Level 1")
.setMessage("Level Completed")
.setPositiveButton("Why should I stop Playing?", null)
.setNegativeButton("Tired to go on", null).show();
HideAllButton();
}
}
}
答案 0 :(得分:0)
您没有创建对象并将其分配给实例成员,而是创建了一个被遗忘的局部变量'当onCreate完成执行时。
更改行:
TextView Txt_EarnedPoint=(TextView ) findViewById(R.id.textView1);
要:
Txt_EarnedPoint=(TextView ) findViewById(R.id.textView1);