在下面的代码中仍然出现java.lang.StringIndexOutOfBoundsException: index=0 length=0错误if (result.charAt(0) =='Y')
还有其他更好的方法来检查空字符串if (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();
}