我有一個非常簡單的應用程序,兩個buttons
和一個text
。我按一個,text
上的數字就會上升。另一個使數量減少。這是我的代碼。應用程序一直停止,我不知道發生了什麼
package com.bryantpc.itemcounter;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.bryantpc.itemcounter.R;
public class IC_MAIN extends ActionBarActivity {
private int Amount1 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button Button1 = (Button)findViewById(R.id.button1);
final Button Button2 = (Button)findViewById(R.id.button2);
final TextView TextView1 = (TextView)findViewById(R.id.textView1);
Button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Amount1++;
TextView1.setText(Amount1);
}
});
Button2.setOnClickListener(new OnClickListener() {
public void onClick (View v) {
Amount1--;
TextView1.setText(Amount1);
}
});
每當我按下其中一個按鈕,應用程序就停止工作。任何人都知道發生了什麼事? P.S我沒有LogCat,因爲我的模擬器不工作我在手機上運行APK。
http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve命名類和變量 - 這 – nhaarman