I am new to this android studio and I try to make a temperature converter the problem is that no matter how hard I try to get this error it is assumed that the whole program should do object oriented
01-29 07: 44: 26.967 12711-12711 / com.example.brolix.ctemperature E / AndroidRuntime: FATAL EXCEPTION: main Process: com.example.brolix.ctemperature, PID: 12711 java.lang.NumberFormatException: Invalid double: "" at java.lang.StringToReal.invalidReal (StringToReal.java:63) at java.lang.StringToReal.parseDouble (StringToReal.java:267) at java.lang.Double.parseDouble (Double.java301) at com.example.brolix.ctemperatura.MainActivity $ 3.onEditorAction (MainActivity.java:66) at android.widget.TextView.onEditorAction (TextView.java:4794) at com.android.internal.widget.EditableInputConnection.performEditorAction (EditableInputConnection.java:139) at com.android.internal.view.IInputConnectionWrapper.executeMessage (IInputConnectionWrapper.java:304) at com.android.internal.view.IInputConnectionWrapper $ MyHandler.handleMessage (IInputConnectionWrapper.java:78) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:135) at android.app.ActivityThread.main (ActivityThread.java:5910) at java.lang.reflect.Method.invoke (Native Method) at java.lang.reflect.Method.invoke (Method.java:372) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)
This is my main activity, I understand that my problem is the data conversion of my method (double)
EditText C, F, K;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
C = findViewById(R.id.celciusnumero);
F = findViewById(R.id.farennumero);
K = findViewById(R.id.kelvinumero);
final celcius c = new celcius();
c.setLetra('C');
final fahrenheit f = new fahrenheit();
f.setLetra('F');
final kelvin k = new kelvin();
k.setLetra('K');
try {
C.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
k.setNumero(Double.parseDouble(K.getText().toString()));
f.setNumero(Double.parseDouble(F.getText().toString()));
c.conversion(f);
F.setText(f.getNumero().toString());
c.conversion(k);
K.setText(k.getNumero().toString());
return false;
}
});
F.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
k.setNumero(Double.parseDouble(K.getText().toString()));
c.setNumero(Double.parseDouble(C.getText().toString()));
f.conversion(c);
C.setText(c.getNumero().toString());
f.conversion(k);
K.setText(k.getNumero().toString());
return false;
}
});
K.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
f.setNumero(Double.parseDouble(F.getText().toString()));
c.setNumero(Double.parseDouble(C.getText().toString()));
k.conversion(c);
C.setText(c.getNumero().toString());
k.conversion(f);
F.setText(f.getNumero().toString());
return false;
}
});
} catch (NumberFormatException e) {
}
}