2012-03-15 22 views
-3

私は奇妙な問題があります。私のコードのIF条件が機能しません。条件が偽であってもif条件に入る。Android: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; 
        } 
       } 

とも私はそれがエラーを示しなステートメント他に追加します。

おかげ

+0

..行の末尾から;を削除し、以下の答えをフォローし、それが動作するはずです。 – Deva

+0

どうしたら 'if(arrIngrName.contains(Global.shopping_name.get(i)));'行 –

+6

はブロックを実行する前にif文が終了したため、 ';'を削除しました –

答えて

2

IFステートメントの最後にセミコロンがあるので、

 if(arrIngrName.contains(Global.shopping_name.get(i))); 
+3

ありがとうございます。私の愚かな間違い。私はこれで1時間を過ごす。 –

+1

LOL。 Dは誰にも起こります。 – Rudy

3

あなたはセミコロンを保ちました。の末尾がの場合となります。最初に取り外します。

2
if(arrIngrName.contains(Global.shopping_name.get(i))); 

関連する問題