代码运行良好.. 这是一个简单的计算应用程序。
不幸的是,在我改变了一些东西后它停止了工作..问题是我不知道这个东西..
这是我的代码...
package com.bogaza.barazileyyecalc;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
//declarations..
final TextView lbl1 = (TextView) findViewById(R.id.textView1);
final TextView lbl2 = (TextView) findViewById(R.id.textView2);
final EditText txt1 = (EditText) findViewById(R.id.editText1);
final EditText txt2 = (EditText) findViewById(R.id.editText2);
final Button btn1 = (Button) findViewById(R.id.button1);
final TextView lbl3 = (TextView) findViewById(R.id.textView3);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// click button to get numbers from edittexts and add them to textviews ..
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(v.getId() == R.id.button1){
int value1 = (int) ((txt1.getText().toString()
.equals("")) ? 0 : Double.valueOf(txt1.getText().toString()));
int value2 = (int) ((txt2.getText().toString()
.equals("")) ? 0 : Double.valueOf(txt2.getText().toString()));
lbl3.setText(String.valueOf(value1 + value2));
}
}
}); ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
它工作正常..我试图改变布局并做出更好的设计..之后问题发生了..现在当我点击运行时..它出现在设备上..并直接崩溃..