Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android string
answer.setText(Double.toString(calculate(firstUnit.getSelectedItem().toString(), secondUnit.getSelectedItem().toString(), Double.parseDouble(unitSize.getText().toString()))));
 
Here is
public double calculate(String unit1, String unit2, double d){
    return 1.23;
}
 

It gives a number format exception and 1.23 is just a number i gave for testing purposes. Assume that answer is a textview, and firstUnit and secondUnit are spinners and unitSize is an edittext widget.
Posted 20-Jul-11 12:55pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I bet it's one if the given arguments that fail. Please try to format your code like this:
double dUnitSize = Double.parseDouble(unitSize.getText().toString());
double dValue = calculate(
      firstUnit.getSelectedItem().toString(),
      secondUnit.getSelectedItem().toString(),
      dUnitSize
);
answer.setText(dValue);
you'll soon find out which line the problem is.
  Permalink  
v3
Comments
Matias Grioni at 21-Jul-11 12:22pm
   
the problem is that this is in an onItemSelected() method, and i didn't know that it was called when the program started, and since unitSize was = to "" it gave error, so i just used try/catch block and its perfect
 
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 525
1 Maciej Los 319
2 BillWoodruff 174
3 Suraj Sahoo | Coding Passion 170
4 /\jmot 152
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 21 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100