それぞれ異なる数字(0〜9)のボタンがたくさんあるアプリのようなものを作成しています。ボタンをクリックすると、その番号を edittext フィールドに表示したいと思います。一種の電卓です。以下は私のコードです:
public class GameActivity extends Activity {
TextView timer;
Button button1;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameactivity);
Intent mIntent = getIntent();
int seconds = getIntent().getIntExtra("seconds", 0);
EditText et = (EditText) findViewById(R.id.editText1);
final TextView timer = (TextView) findViewById(R.id.textViewtimer);
new CountDownTimer(seconds, 1000) {
public void onTick(long millisUntilFinished) {
timer.setText("Seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
Intent intent = new Intent(GameActivity.this, Main.class);
startActivity(intent);
}
}.start();
}
public void one (View v){
int n = 1;
et.setText(n);
}
これが私が得ているエラーです:
09-12 12:21:25.778: E/AndroidRuntime(3658): FATAL EXCEPTION: main
09-12 12:21:25.778: E/AndroidRuntime(3658): java.lang.IllegalStateException: Could not execute method of the activity
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.view.View$1.onClick(View.java:2144)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.view.View.performClick(View.java:2485)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.view.View$PerformClick.run(View.java:9080)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.os.Handler.handleCallback(Handler.java:587)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.os.Looper.loop(Looper.java:123)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-12 12:21:25.778: E/AndroidRuntime(3658): at java.lang.reflect.Method.invokeNative(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658): at java.lang.reflect.Method.invoke(Method.java:507)
09-12 12:21:25.778: E/AndroidRuntime(3658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-12 12:21:25.778: E/AndroidRuntime(3658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-12 12:21:25.778: E/AndroidRuntime(3658): at dalvik.system.NativeStart.main(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658): Caused by: java.lang.reflect.InvocationTargetException
09-12 12:21:25.778: E/AndroidRuntime(3658): at java.lang.reflect.Method.invokeNative(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658): at java.lang.reflect.Method.invoke(Method.java:507)
09-12 12:21:25.778: E/AndroidRuntime(3658): at android.view.View$1.onClick(View.java:2139)
09-12 12:21:25.778: E/AndroidRuntime(3658): ... 11 more
09-12 12:21:25.778: E/AndroidRuntime(3658): Caused by: java.lang.NullPointerException
09-12 12:21:25.778: E/AndroidRuntime(3658): at com.dtan.mathwiz.GameActivity.one(GameActivity.java:42)
09-12 12:21:25.778: E/AndroidRuntime(3658): ... 14 more