0

The java code for a currency convertor(pounds to dollars):

package com.example.currencyconverter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
    
public class MainActivity extends AppCompatActivity {
    public void convert(View view){
      Log.i("info", "button works!");
      EditText editText = findViewById(R.id.editText);
      String amtInPounds = editText.getText().toString();
      double amtInPoundsDouble = Double.parseDouble(amtInPounds);
      double amtInDollarDouble = amtInPoundsDouble * 1.3;
      String amtInDollarString = Double.toString(amtInDollarDouble);
         Log.i("info", amtInDollarString);
         
     }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

logcat Error:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.currencyconverter, PID: 7262

  • The crash log will tell you the exact problem, see [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). – Markus Kauppinen Jul 28 '20 at 14:32
  • The code will surely crash for example if the `EditText` is empty. – Markus Kauppinen Jul 28 '20 at 14:45

0 Answers0