-4
有一个机器人应用(Android工作室)在Java语言我试图理解的代码片段,有17号作为数组的索引,因为我以粗体突出显示行代码,我尝试了很多,但我不明白那是什么号,这里是代码段的Android用java
protected void onPostExecute(String result)
{
**if(result == "0")**
{
Context context = getApplicationContext();
CharSequence text = "Invalid IP address";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else
{
char[] charArray = result.toCharArray();
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG;
**if(charArray[17]=='0')**
{
CharSequence text = "Invalid Password";
Toast toast = Toast.makeText(context, text, duration);
toast.show();
_logged_in = false;
}
**if(charArray[17]=='1')**
{
CharSequence text = "You logged in successfully";
Toast toast = Toast.makeText(context, text, duration);
toast.show();
_logged_in = true;
startActivity(intent);
}
}
在此先感谢
这意味着charArray'的'18字符,所以result'的'18字符注意。 – mmking
这是相当糟糕的 - 2件事情伸出。首先,它应该是result.equals(“0”)不是结果===“0”。其次,确定成功的两个if语句是排他性的,所以第二个[if(charArray [17] =='1')]应该是'else if'而不是'if'。 – KevinDTimm
绝对应该像上面提到的那样修复字符串。此外,似乎结果的第18个字符存储登录是否成功以及是否存在IP地址错误。所有这一切都在我猜测的AsyncTask结尾。不是我最喜欢的实现。结果应该是一个常数整数或更好的枚举。 – napkinsterror