Android: если условие не работает - PullRequest
0 голосов
/ 15 марта 2012

У меня странная проблема. ЕСЛИ условие в моем коде не работает. оно попадает в условие if, даже если условие ложно.

Я проверяю значения в режиме отладки.

Вот мой код:

for (int i = 0; i < Global.shopping_name.size(); i++) {         
        try {
            double num;
            long iPart;
            double fPart;
            String fractP = "";

            // Get user input
            num = Double.parseDouble(Global.shopping_ammount.get(i));

            if(arrIngrName.contains(Global.shopping_name.get(i)));
            {
//              Get index of element
                indx = arrIngrName.indexOf(Global.shopping_name.get(i));

                if (arrIngrType.get(indx).equalsIgnoreCase(Global.shopping_type.get(i)))    {

                    preValue = Double.parseDouble(arrIngrMeasure.get(i));
                    newValue =  preValue + num;
                    num = newValue;                     
                }                   
            }

            iPart = (long) num;
            fPart = num - iPart;
            System.out.println("Integer part = " + iPart);
            System.out.println("Fractional part = " + fPart);            

            /////////////////////////////////////

            if  (0.062 >= fPart ) {
                fractP = "1/16";
            } else if (0.066 >= fPart) {
             fractP = "1/15";
            } else if (0.100 >= fPart) {
             fractP = "1/10";
            } else if (0.125 >= fPart) {
             fractP ="1/8";
            } else if (0.133 >= fPart) {
             fractP = "2/15";
            } else if (0.187 >= fPart) {
             fractP = "3/16";
            } else if (0.200 >= fPart) {
             fractP ="1/5";
            } else if (0.250 >= fPart) {
             fractP = "1/4";
            } else if (0.266 >= fPart) {
             fractP ="4/15";
            } else if (0.300 >= fPart) {
             fractP = "3/10";
            } else if (0.312 >= fPart) {
             fractP ="5/16";
            } else if (0.333 >= fPart) {
             fractP = "1/3";
            } else if (0.375 >= fPart) {
             fractP ="3/8";
            } else if (0.400 >= fPart) {
             fractP = "2/5";
            } else if (0.437 >= fPart) {
             fractP ="7/16";                
            } else if (0.466 >= fPart) {
             fractP ="7/15";                
            } else if (0.500 >= fPart) {
             fractP = "1/2";
            } else if (0.533 >= fPart) {
             fractP = "8/15";
            } else if (0.562 >= fPart) {
             fractP = "9/16";               
            } else if (0.600 >= fPart) {
             fractP ="3/5";             
            } else if (0.625 >= fPart) {
             fractP = "5/8";                
            } else if (0.666 >= fPart) {
             fractP ="2/3";
            } else if (0.687 >= fPart) {
             fractP = "11/16";
            } else if (0.700 >= fPart) {
             fractP ="7/10";
            } else if (0.733 >= fPart) {
             fractP ="11/15";
            } else if (0.750 >= fPart) {
             fractP ="3/4";
            } else if (0.800 >= fPart) {
             fractP ="4/5";
            } else if (0.812 >= fPart) {
             fractP = "13/16";              
            } else if (0.866 >= fPart) {
             fractP ="13/15";
            } else if (0.875 >= fPart) {
             fractP = "3/4";
            } else if (0.900 >= fPart) {
             fractP ="9/10";
            } else if (0.933 >= fPart) {
             fractP ="14/15";
            } else if (0.937 >= fPart) {
             fractP ="15/16";
            }           

            /////////////////////////////////////               

            map = new HashMap<String, String>();
                map.put("rowid", "" + (i+1));

                if (fPart > 0 && iPart > 0) {
            map.put("col_1",iPart + " " +fractP + " " + Global.shopping_type.get(i));
                } else if (fPart > 0 && iPart == 0) {
                    map.put("col_1",fractP + " " + Global.shopping_type.get(i));
            } else {
                map.put("col_1",iPart + " " + Global.shopping_type.get(i));
            }                   

                map.put("col_2", "    ");
                map.put("col_3", Global.shopping_name.get(i) );
                map.put("col_4", "Brukes i "+ Global.shopping_recipe.get(i));

            if(arrIngrName.contains(Global.shopping_name.get(i)));
                {
//                  Get index of element
                    indx = arrIngrName.indexOf(Global.shopping_name.get(i));

                    if (arrIngrType.get(indx).equalsIgnoreCase(Global.shopping_type.get(i))) {
//                      Do nothing
                        Log.e("SAME", "SAME");
                    } else {
                        fillMaps.add(map);
                    }

                }

                if(!arrIngrName.contains(Global.shopping_name.get(i)));
                {
//              
                        fillMaps.add(map);                      
                }

//                      Add To array
                       arrIngrMeasure.add(Global.shopping_ammount.get(i));
                        arrIngrName.add(Global.shopping_name.get(i));
                        arrIngrType.add(Global.shopping_type.get(i));

                        Log.d("SIZE : ", fillMaps.toString());

        } catch(Exception e) {
            e.printStackTrace();
        }
        }
        }
                return null;                
        }

Этот код не работает:

  if(arrIngrName.contains(Global.shopping_name.get(i)));
            {
//              Get index of element
                indx = arrIngrName.indexOf(Global.shopping_name.get(i));

                if (arrIngrType.get(indx).equalsIgnoreCase(Global.shopping_type.get(i)))
                {

                    preValue = Double.parseDouble(arrIngrMeasure.get(i));
                    newValue =  preValue + num;
                    num = newValue;
                    }
                }

, а также, когда я добавляю остальное, оно показывает ошибку.

Спасибо

Ответы [ 3 ]

3 голосов
/ 15 марта 2012

Вы оставили точка с запятой; в конце , если .Сначала удалите.

2 голосов
/ 15 марта 2012
if(arrIngrName.contains(Global.shopping_name.get(i)));

Удалить ; с конца строки ..

2 голосов
/ 15 марта 2012

Потому что у вас точка с запятой в конце оператора IF?

      if(arrIngrName.contains(Global.shopping_name.get(i)));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...