0
所以每次我運行此代碼我的Android應用unexpectdly停止,我不明白爲什麼時間...Android應用程序總是意外停止,試圖做事件處理程序?
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;
public class TheStupidTest extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView text1 = (TextView) findViewById(R.id.TextView01);
text1.setText("well this works at least");
Button yButton = (Button) findViewById(R.id.button_yellow);
yButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.equals(MotionEvent.ACTION_UP)) {
text1.setText("You pressed the yellow button");
return true;
}
return false;
}
});
}
}
查看來自Pentium10的關於如何調試Android應用的帖子 http://stackoverflow.com/questions/3222608/android-error-the-application-has-stopped-unexpectedly-please-try-again/3223115# 3223115 – ccheneson 2010-07-11 21:12:40
你會看看DDMS和logcat來檢查問題http://goo.gl/i9by – 2010-07-11 21:21:10
爲什麼一個按鈕的OnTouchListener而不是'OnClickListener'? – adamp 2010-07-11 22:54:39