我的应用程序无法打开并强制关闭

时间:2012-12-03 10:44:19

标签: android

我的应用程序在打开后立即关闭, 这是我的第一个应用程序,我试图找到错误,但我不能 自从启动这个应用程序以来我附加了log cat:

          12-03 16:04:54.040: W/dalvikvm(8798): threadid=1: thread exiting with uncaught exception (group=0x40018578)
          12-03 16:04:54.040: E/AndroidRuntime(8798): FATAL EXCEPTION: main
          12-03 16:04:54.040: E/AndroidRuntime(8798): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sditya.quadratic.equation/com.sditya.quadratic.equation.Quadratic}: java.lang.NullPointerException
          ...
          12-03 16:04:54.040: E/AndroidRuntime(8798): Caused by: java.lang.NullPointerException
          12-03 16:04:54.040: E/AndroidRuntime(8798):   at com.sditya.quadratic.equation.Quadratic.initialize(Quadratic.java:58)

初始化方法:

private void initialize() { 
// TODO Auto-generated method stub
tr = (TextView) findViewById(R.id.tvResults); 
xs = (EditText) findViewById(R.id.editText1);
x = (EditText) findViewById(R.id.editText2); 
c = (EditText) findViewById(R.id.editText3); 
b.setOnClickListener(this); 
} 

修改:已解决,我忘了按下按钮'b'。

1 个答案:

答案 0 :(得分:4)

initialize方法中,您需要在设置侦听器之前设置按钮变量..

private void initialize() { 
// TODO Auto-generated method stub
tr = (TextView) findViewById(R.id.tvResults); 
xs = (EditText) findViewById(R.id.editText1);
x = (EditText) findViewById(R.id.editText2); 
c = (EditText) findViewById(R.id.editText3); 

b = (Button) findViewById(R.id.button1); 
b.setOnClickListener(this); 
}