Tag Archives: index0size0

How to Solve Console error: index: 0, size: 0

Source code: service implementation class:

       String select_sql = "select cguid,(case isrz when 1 then 'PASS' when 0 then 'FAIL' end) as smrzzt from t_jb_user where mobile=?"; List<Map<String,Object>> list = ydbsDaoI.findList(select_sql, new Object[]{phoneno});//Take out the result of the query String cguid = list.get(0).get("cguid")==null?"":list.get(0).get("cguid").toString(); String smrzzt = list.get(0).get("smrzzt")==null?"":list.get(0).get("smrzzt").toString();

An error is reported because no judgment is made on whether the fetched result is empty and fetched directly   index:0,size:0

It can operate normally after adding if judgment:

        String select_sql = "select cguid,(case isrz when 1 then 'PASS' when 0 then 'FAIL' end) as smrzzt from t_jb_user where mobile=?"; List<Map<String,Object>> list = ydbsDaoI.findList(select_sql, new Object[]{phoneno});
       if(list != null && list.size() > 0){
 //Take out the result of the query   String cguid = list.get(0).get("cguid")==null?"":list.get(0).get("cguid").toString();    String smrzzt = list.get(0).get("smrzzt")==null?"":list.get(0).get("smrzzt").toString();
        } else {
           return;
        }