I am developing an ATM android app and whenever the app opens it crashes. Here is my code:
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");
}
}
}
Note: I dont rum on an emulator so I dont know what exception or error I am getting.
Aucun commentaire:
Enregistrer un commentaire