Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓:如果条件不起作用_Java_If Statement_Conditional Statements - Fatal编程技术网

Java 安卓:如果条件不起作用

Java 安卓:如果条件不起作用,java,if-statement,conditional-statements,Java,If Statement,Conditional Statements,我有一个奇怪的问题。如果代码中的条件不起作用。即使条件为false,它也会进入if条件 我在调试模式下检查这些值 这是我的密码: for (int i = 0; i < Global.shopping_name.size(); i++) { try { double num; long iPart; double fPart; String fractP = "

我有一个奇怪的问题。如果代码中的条件不起作用。即使条件为false,它也会进入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;                
        }
另外,当我添加else语句时,它会显示错误


谢谢你保留了分号在if语句末尾。首先删除它。

因为IF语句末尾有分号

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

删除
从行尾开始。

按照下面的答案进行操作,它应该会起作用。如果(arrIngrName.contains(Global.shopping_name.get(i)),这个
怎么办行删除
因为if语句在执行块之前终止
      if(arrIngrName.contains(Global.shopping_name.get(i)));
if(arrIngrName.contains(Global.shopping_name.get(i)));