I've been trying to get a simple calculator app working for the past couple of days but I can't seem to narrow the problem. I am a total newbie at android development so there could be a problem with my mainActivity code but I've made some precautions and tried them out. I tried deleting all the code I personally made and redoing the whole emulator process and the app still does not open. I have tried deleting the app on the emulator and restarting, I tried rebuilding, cleaning and turning off instant run. I don't believe it's an Android Studio issue because I created a new project and tossed some XMl elements in and it ran perfectly fine on my computer. I think there's something wrong with my code.
I have deleted code I've written and running the application to no avail. I have uninstalled the application on the emulator and ran it again. I have trying rebuilding and cleaning the project. I have tried syncing the gradle. And I have tried turning on instant run. By the title this may seem like the same thing but it isn't.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
buttonAdd = findViewById(R.id.Add_Button);
buttonSub = findViewById(R.id.Sub_Button);
buttonDiv = findViewById(R.id.Div_Button);
buttonMult = findViewById(R.id.Mul_Button);
mText = findViewById(R.id.Answer);
//Conversion of textview to double
UserInput = findViewById(R.id.FirstNumber);
UserInput2 = findViewById(R.id.SecondNumber);
userinput = Double.parseDouble(UserInput.getText().toString());
userinput2 = Double.parseDouble(UserInput2.getText().toString());
//functions for the operations.
buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View a){
mText.setText("Answer = " + Double.toString((userinput+userinput2)));
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mText.setText("Answer = " + Double.toString((userinput - userinput2)));
}
});
buttonMult.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mText.setText("Answer = " + Double.toString((userinput*userinput2)));
}
});
buttonDiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mText.setText("Answer = " + Double.toString ((userinput / userinput2)));
}
});
}
}
I would expect to run the program but it doesn't run. I'm hoping that the above code is enough because I must be making an obvious mistake.
LogCat: