Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.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
Android中java.lang.StringIndexOutOfBoundsException的完整验证检查_Android_Null_Android Asynctask_Indexoutofboundsexception - Fatal编程技术网

Android中java.lang.StringIndexOutOfBoundsException的完整验证检查

Android中java.lang.StringIndexOutOfBoundsException的完整验证检查,android,null,android-asynctask,indexoutofboundsexception,Android,Null,Android Asynctask,Indexoutofboundsexception,仍在获取java.lang.StringIndexOutOfBoundsException:index=0 length=0下面代码中的错误,位于if(result.charAt(0)='Y') 如果(result==null | | | result.isEmpty()),还有其他更好的方法检查中的空字符串吗?由于某些原因,未拾取空字符串“result”或activity.finish()未执行,下一个if语句是否已执行?请帮忙 @Override protected void onP

仍在获取java.lang.StringIndexOutOfBoundsException:index=0 length=0下面代码中的错误,位于
if(result.charAt(0)='Y')

如果(result==null | | | result.isEmpty()),还有其他更好的方法检查
中的空字符串吗?由于某些原因,未拾取空字符串“result”或
activity.finish()未执行,下一个if语句是否已执行?请帮忙

@Override
    protected void onPostExecute(String result) {

        //check if result null or empty
        if (result == null || result.isEmpty()) {

            Toast.makeText(context, "Could Not Check For Updates, Please Try Again. Closing Application.", Toast.LENGTH_LONG).show();
            activity.finish();
        }           
        //update available
        if (result.charAt(0) =='Y') {

            UpdateAlert();
        }
        //no update available
        else if (result.charAt(0) =='N') {

            Toast.makeText(context, "No Updates Available", Toast.LENGTH_SHORT).show();             
        }
        else {

            Toast.makeText(context, "Could Not Check For Updates, Please Try Again. Closing Application : " + result, Toast.LENGTH_LONG).show();
            activity.finish();
        }   

遇到下面修改的无效结果时,尝试从方法返回

//check if result null or empty         
           if (result == null || result.isEmpty()) {              
                Toast.makeText(context, "Could Not Check For Updates, Please Try Again. Closing Application.", Toast.LENGTH_LONG).show();             
                activity.finish();         
                return;
           }  

试着接受你合适的答案,让你的问题更接近你。
   if (result == null || result.trim().length()==0) {
         Toast.makeText(context, "Could Not Check For Updates, Please Try Again. Closing  Application.", Toast.LENGTH_LONG).show();
            activity.finish();
        }           
        //update available
        else if (result.charAt(0) =='Y') {
        ^^^^ 
            UpdateAlert();
        }