1

I am trying with some calculating codes ... but in some devices the app just broke down ... and the message was invalid double value

the related code as the following

final double totalValue; double fValue1 = value1* amount1 /totalAmout;

final double value1  ;
                  final double value2  ;
                  final double value3  ;
                  final double value4  ;
                  final double value5  ;
                  final double value6  ;
                  final double value7  ;
                  final double value8  ;
                  final double value9  ;
                  final double value10 ;
                  final double totalValue;
                  if (firstSp.getSelectedItemPosition()  >0 & firstSp  .getSelectedItemPosition() <= elementsArraysArray.length  )  { value1 
= Double.parseDouble(elementsArraysArray[firstSp  .getSelectedItemPosition() -1][i -1]);       if (amount1 ==0 || amount1ET.getText().toString().isEmpty() ){amountB = false;}      }else if (firstSp  .getSelectedItemPosition() == elementsArraysArray.length + 1) {value1  = addedOneArrayList.get(newALindex).getValueOfElement(); if (amount1
==0|| amount1ET.getText().toString().isEmpty() ){amountB = false;}} else if (firstSp  .getSelectedItemPosition() == elementsArraysArray.length + 2) {value1   = addedTwoArrayList.get(newALindex).getValueOfElement(); if (amount1
==0|| amount1ET.getText().toString().isEmpty() ){amountB = false;}}  else if (firstSp  .getSelectedItemPosition() == elementsArraysArray.length + 3) {value1  = addedThreeArrayList.get(newALindex).getValueOfElement(); if (amount1
==0|| amount1ET.getText().toString().isEmpty() ){amountB = false;}}  else if (firstSp  .getSelectedItemPosition() == elementsArraysArray.length + 4) {value1  = addedFourArrayList.get(newALindex).getValueOfElement(); if (amount1
==0|| amount1ET.getText().toString().isEmpty() ){amountB = false;}} else {value1  = 0;}
                 
                    double fValue2 = value2* amount2 /totalAmout;
                    double fValue3 = value3* amount3 /totalAmout;
                    double fValue4 = value4* amount4 /totalAmout;
                    double fValue5 = value5* amount5 /totalAmout;
                    double fValue6 = value6* amount6 /totalAmout;
                    double fValue7 = value7* amount7 /totalAmout;
                    double fValue8 = value8* amount8 /totalAmout;
                    double fValue9 = value9* amount9 /totalAmout;
                    double fValue10=value10*amount10 /totalAmout;

                    totalValue = fValue1 +fValue2 +fValue3  +fValue4   +fValue5  +fValue6  +fValue7  +fValue8  +fValue9  +fValue10;

final DecimalFormat form = new DecimalFormat("#.##"); 
finalArrayList.add(new SelectedItem(contentElmntsArray[(i / 2) - 1], Double.parseDouble(form.format(totalValue))));

could you guys please advice

UPDATE: the mistake was here Double.parseDouble(elementsArraysArray[firstSp .getSelectedItemPosition() -1][i -1]); in some old devices where the language of divice is Arabic , the device translate the number (inside the String) so it will not be able to extracted as a type of number variable

Bahaa
  • 11
  • 3
  • 1
    the formatting on your code is very difficult to read, you should really consider [formatting it](https://stackoverflow.com/questions/16580171/code-formatting-shortcuts-in-android-studio-for-operation-systems) – a_local_nobody Nov 01 '20 at 18:25
  • I track the problem ... its happen for some values that extract from String and the number is Integer and doesn't have a decimal point >> but still don't know how to fix it – Bahaa Nov 02 '20 at 07:41

0 Answers0