0

我的应用程序一打开它就会关闭,这是我的第一个应用程序,我试图找到错误,但是自从启动这个应用程序以来我无法附加日志猫:

          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”充气。

4

1 回答 1

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); 
}
于 2012-12-03T10:53:25.147 回答