Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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 死代码android setMultiChoiceItems_Java_Android_Dialog_Dead Code - Fatal编程技术网

Java 死代码android setMultiChoiceItems

Java 死代码android setMultiChoiceItems,java,android,dialog,dead-code,Java,Android,Dialog,Dead Code,我使用setMultiChoiceItems作为对话框中的列表。 单击“确定”时,代码为 .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int which){ String[] res = null; for(int i=-1,l=usrCats.length; ++i<l;){

我使用setMultiChoiceItems作为对话框中的列表。 单击“确定”时,代码为

 .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
String[] res = null;
for(int i=-1,l=usrCats.length; ++i<l;){
    if(selections[i])
       res[i] = usrCats[i].toString();
}
if(res != null && res.length>0)
   dbManager.removeUserShoppingCategories(res);
}       
})
.setPositiveButton(R.string.alert\u删除,新建DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
字符串[]res=null;
对于(int i=-1,l=usrCats.length;++i0)
dbManager.removeUserShoppingCategories(res);
}       
})
我想检查是否使用
if(选项[i]
选择了某个项目,如果是,请在 串

我在
res[i]=usrCats[i].toString()中有一个空指针访问权限,在最后一个if语句中有一个死代码警告

我使用最后一个if来检查是否有任何选择,以便调用我的方法

我做错了什么?

.setPositiveButton(R.string.alert\u remove,new DialogInterface.OnClickListener(){
        .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
        String[] res = null; // you initialised it with null
        for(int i=-1,l=usrCats.length; ++i<l;){ /*this line and the below line are condition 
    statemnts whose code may not run. so there are chances that your **res** will 
    remain initialised with null*/
            if(selections[i])
               res[i] = usrCats[i].toString();
        }
        if(res != null && res.length>0)// so here it shows a dead code warning.
           dbManager.removeUserShoppingCategories(res);
        }       
        })
public void onClick(DialogInterface dialog,int which){ String[]res=null;//您用null初始化了它 for(int i=-1,l=usrCats.length;++i0)//因此这里显示了一个死代码警告。 dbManager.removeUserShoppingCategories(res); } })
我仍然怀疑这段代码是否编译为for(int i=-1,l=usrCats.length;++i你错得很厉害,你应该试试。它非常有效。我该怎么办?你的看法是什么?