I've just started to dabble in Java so please reserve the lectures on bad code practice, for now.
I have been having a lot of issues with my most recent project to begin with I wasn't able to get any of the layout objects to show, at all. I resolved that issue after some hours of googling.
However, now I have an issue with actually trying to run my project on an emulator. I've seen advice on other threads that say to turn off instant run, delete .idea & gradle folders then rebuild and sync with gradle etc. None of that has worked for me so far.
I would just like to ask if there is anything wrong with my code (beside the fact that it's not great in terms of practice/efficiency) that would prevent my code from running. (please see below the code for the event log)
The reason behind my confusion is that I'm getting no errors when Building my project however I'm unable to run the application (have also tried building the APK file and running it on my actual phone but that doesn't work either).
package total.register.registertotal;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Define all of the input variables.
final EditText Fifties = (EditText) findViewById(R.id.Fifties);
final EditText Twenties = (EditText) findViewById(R.id.Twenties);
final EditText Tens = (EditText) findViewById(R.id.Tens);
final EditText Fives = (EditText) findViewById(R.id.Fives);
final EditText Ones = (EditText) findViewById(R.id.Ones);
final EditText Halfs = (EditText) findViewById(R.id.Halfs);
final EditText Fifths = (EditText) findViewById(R.id.Fifths);
final EditText Tenths = (EditText) findViewById(R.id.Tenths);
final EditText Twentieths = (EditText) findViewById(R.id.Twentieths);
final EditText Hundredths = (EditText) findViewById(R.id.Hundredths);
final EditText Total = (EditText) findViewById(R.id.Total);
//Convert them all into strings
final String StrFifties = Fifties.getText().toString();
final String StrTwenties = Twenties.getText().toString();
final String StrTens = Tens.getText().toString();
final String StrFives = Fives.getText().toString();
final String StrOnes = Ones.getText().toString();
final String StrHalfs = Halfs.getText().toString();
final String StrFifths = Fifths.getText().toString();
final String StrTenths = Tenths.getText().toString();
final String StrTwentieths = Twentieths.getText().toString();
final String StrHundredths = Hundredths.getText().toString();
//Convert them all into numbers to be used in addition.
final int IntFifties = Integer.parseInt(StrFifties);
final int IntTwenties = Integer.parseInt(StrTwenties);
final int IntTens = Integer.parseInt(StrTens);
final int IntFives = Integer.parseInt(StrFives);
final int IntOnes = Integer.parseInt(StrOnes);
final int IntHalfs = Integer.parseInt(StrHalfs);
final int IntFifths = Integer.parseInt(StrFifths);
final int IntTenths = Integer.parseInt(StrTenths);
final int IntTwentieths = Integer.parseInt(StrTwentieths);
final int IntHundredths = Integer.parseInt(StrHundredths);
//Create constants
final int Fifty = 50;
final int Twenty = 20;
final int Ten = 10;
final int Five = 5;
final int One = 1;
final Button SummariseRegister = (Button) findViewById(R.id.Calculate);
SummariseRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
double TotFifties = 0;
if(!StrFifties.matches("")){
TotFifties = IntFifties * Fifty;
}
int TotTwenties = 0;
if(!StrTwenties.matches("")){
TotTwenties = IntTwenties * Twenty;
}
int TotTens = 0;
if(!StrTens.matches("")){
TotTens = IntTens * Ten;
}
int TotFives = 0;
if(!StrFives.matches("")){
TotFives = IntFives * Five;
}
int TotOnes = 0;
if(!StrOnes.matches("")){
TotOnes = IntOnes * One;
}
double TotHalfs = 0;
if(!StrHalfs.matches("")){
TotHalfs = IntHalfs * (0.5);
}
double TotTenths = 0;
if(!StrTenths.matches("")){
TotTenths = IntTenths * (0.1);
}
double TotTwentieths = 0;
if(!StrTwentieths.matches("")){
TotTwentieths = IntTwentieths * (0.2);
}
double TotHundredths = 0;
if(!StrHundredths.matches("")){
TotHundredths = IntHundredths * (0.01);
}
//double Total = TotFifties + TotTwenties + TotTens + TotFives + TotOnes + TotHalfs + TotTenths + TotHundredths + TotTwentieths;
double Total = TotFifties;
}catch(Exception e){
Total.setText("Error calculating result.");
}
}
});
}
}
Event Log:
15/10/2018 19:24 IDE and Plugin Updates: Android Studio is ready to update.
19:24 Gradle sync started
19:24 Project setup started
19:24 Gradle sync finished in 1s 313ms (from cached state)
19:31 * daemon not running; starting now at tcp:5037
19:31 * daemon started successfully
19:31 Executing tasks: [:app:assembleDebug]
19:31 Emulator: Process finished with exit code -1073741819 (0xC0000005)
19:31 Gradle build finished in 9s 867ms
19:31 Session 'app': Error Installing APK
I would appreciate very dumbed down answers if any of you could be so kind.
Thank you.