我試圖建立自定義數字選擇器,每次點擊+或 - 按鈕時,我的應用程序崩潰。我在MainActivity.java中沒有收到任何錯誤。 有人知道可能是什麼情況? 下面是代碼:點擊一個按鈕時,應用程序崩潰
public class MainActivity extends Activity {
TextView tvHeight;
int counter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button heightMinus = (Button) findViewById(R.id.height_min);
Button heightPlus = (Button) findViewById(R.id.height_plus);
tvHeight = (TextView) findViewById(R.id.textViewHeight);
heightPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter++;
tvHeight.setText(counter);
}
});
heightMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter--;
tvHeight.setText(counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
你看看logcat輸出了嗎? – donfuxx
你爲什麼把這個標籤標記爲'numberpicker'? – Raghunandan