Caused by: java.lang.NullPointerException错误解析

editText = (EditText) findViewById(R.id.edit);
agnbtn = (Button) findViewById(R.id.agn);
reducebtn = (Button) findViewById(R.id.reduce);
multbtn = (Button) findViewById(R.id.mul);
deletebtn = (Button) findViewById(R.id.delete);
dividebtn = (Button) findViewById(R.id.divide);
equalbtnButton = (Button) findViewById(R.id.equal);
addbtn.setOnClickListener(new addlis());
editText.setOnClickListener(new listener());
reducebtn.setOnClickListener(new reducelis());
multbtn.setOnClickListener(new multlis());
deletebtn.setOnClickListener(new deletelis());
dividebtn.setOnClickListener(new dividelis());

运行后系统和会报错:
08-08 00:42:29.422: E/AndroidRuntime(849): Caused by: java.lang.NullPointerException
08-08 00:42:29.422: E/AndroidRuntime(849):  at com.example.culcalutor1.MainActivity.onCreate(MainActivity.java:43)

空指针异常,这时就要查看自己的程序中是否存在空指针。

如上例所知,addbtn未初始化,这是一个常见的问题。将addbtn初始化就可以解决了。

你可能感兴趣的:(Caused by: java.lang.NullPointerException错误解析)