Android中java.lang.StringIndexOutOfBoundsException的完整验证检查
仍在获取java.lang.StringIndexOutOfBoundsException:index=0 length=0下面代码中的错误,位于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
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();
}