-1

can someone please help me, I am trying to do a simple quadratic equation app, and I can't figure out how to make the double variables get the value from the text inputed in the Edit text field

Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81

1 Answers1

3

Simply take the string value from the EditText and parse it to a Double.

double value = Double.parseDouble(myEditText.getText().toString());
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • What am I doing wrong? the st1, st2 and st3 are the Edi texts @Override public void onClick(View v) { // TODO Auto-generated method stub double a = Double.parseDouble(st1.getText().toString()); double b = Double.parseDouble(st2.getText().toString()); double c = Double.parseDouble(st3.getText().toString()); dis = (b * b - 4 * a * c); d = Math.sqrt(dis); x1 = ((-b + d) / (2.0 * a)); x2 = ((-b - d) / (2.0 * a)); – Sartheris Stormhammer Mar 02 '13 at 14:11
  • @БориславМинчев That looks correct. What error do you get? Edit your question to include the error and relevant code. – Raghav Sood Mar 02 '13 at 14:12
  • Sorry, here is a better view, I am getting errors on st1, st2 and st3 [link](http://img266.imageshack.us/img266/7339/java1.png) – Sartheris Stormhammer Mar 02 '13 at 14:16
  • You haven't declared st1, st2 and st3 anywhere.... – Raghav Sood Mar 02 '13 at 14:24
  • Like this? EditText st1, st2, st3; because the app now crashed when I pressed the button to calculate – Sartheris Stormhammer Mar 02 '13 at 14:26
  • You also have to assign values to them, like you do to the button – Raghav Sood Mar 02 '13 at 14:26