私は最近、Androidアプリケーションの開発方法を学び始めました。私はかなりJavaに堪能ですが、私はまだAndroidとXMLのハングアップのハングアップを取得しようとしています。
だから、事前に助けてくれてありがとう:D!
今は、EditTextウィジェットとボタンを持つアプリケーションを作成しようとしています。現在、私のすべてのコードはボタンのOnClickListenerを作成し、OnClickメソッドを定義しています。なぜ私はそれが強制終了しているのか分かりません。私はいくつかの小さなプログラム(主にボタンを試してみる)を試していましたが、この問題も数回起こっていましたので、このコードに固有のものではないと思います。
ここにコードです:
public class AdditionActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(AdditionActivity.this, "Welcome to Addition Helper!", Toast.LENGTH_SHORT).show();
final EditText answerBox = (EditText) findViewById(R.id.answerBox);
final Button button = (Button) findViewById(R.id.button);
final TextView problem = (TextView) findViewById(R.id.problem);
//
//problem.setText("5+4");
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(AdditionActivity.this, "Started", Toast.LENGTH_SHORT);
String temp = problem.getText().subSequence(0, 1).toString();
int first = Integer.parseInt(temp);
temp = problem.getText().subSequence(2,3).toString();
int second = Integer.parseInt(temp);
int answer = first + second;
if(Integer.parseInt(answerBox.getText().toString()) == answer)
Toast.makeText(AdditionActivity.this, "Correct!!!!!", Toast.LENGTH_SHORT);
else
Toast.makeText(AdditionActivity.this, "WRONG", Toast.LENGTH_SHORT);
}
});
}
}
だから初心者が頻繁に強制終了したり、自分のコードに間違ったことをしているのであれば誰でも知っていれば素晴らしいだろう!私のレイアウトXMLファイルには、EditTextウィジェット、TextViewウィジェット、およびボタンがあります。
もう一度お時間をいただき、本当にありがとうございます。