0
我正在開發一個ATM android應用程序,每當應用程序打開它崩潰。 這裏是我的代碼:Atm android應用程序
public class MainActivity extends AppCompatActivity {
TextView balanceText;
EditText input;
Button withdrawButton;
int balance = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Create the random number
Random number = new Random();
int balance = number.nextInt(10000);
//Initialize the variables
balanceText = (TextView)findViewById(R.id.balanceText);
input = (EditText)findViewById(R.id.input);
withdrawButton = (Button)findViewById(R.id.withdrawButton);
do {
balanceText.setText(balance);
} while (balance > 0);
}
public void withdraw(View view) {
try {
String text = input.getText().toString();
int withdrawal = Integer.parseInt(text);
balance = balance - withdrawal;
if (withdrawal > balance) {
balanceText.setText("Insufficient funds");
}
}
catch (Exception e) {
balanceText.setText("Something went wrong");
}
}
}
注:我不模擬器上進行朗姆酒,所以我不知道我得到什麼異常或錯誤做。
請發表您的崩潰日誌,否則它是不可能告訴什麼導致了問題。謝謝 –
如果您正在設備上運行,請向我們展示logcat。請參閱:[不幸的是,MyApp已停止。我怎樣才能解決這個問題?](http://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this) –
你做雖然看起來像它會阻止主線程永遠......不是一件好事 –