» 首頁 » 討論區 » Android程式設計 »帳號登入程式碼問題

帳號登入程式碼問題

發表人: 訪客
發表時間: 2011-09-05 13:01:23
版大您好 小弟目前在練習帳號登入的語法
但不知道是哪裡出錯 最終顯示都會是N
想請板大幫忙看一下哪裡有錯 謝謝

[sea:javaCode]
HttpPost httpRequest = new HttpPost(uriAPI);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("Account",uid));
nvps.add(new BasicNameValuePair("Passwd",upw));
try
{
httpRequest.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);

if(httpResponse.getStatusLine().getStatusCode()==200)
{
String result= EntityUtils.toString(httpResponse.getEntity());
if(result=="Y")
{
return true ;
}
else
{
return false;
}
}
}
[/sea]
發表人: Seachaos
積分: 2432
發表時間: 2011-09-06 00:20:46
你好,因String的特性
在字串的判斷上建議不要用==的方式

[sea:javaCode]
if (result.equals("Y")){
}
[/sea]
這種方試看看

還有可以把result給dump出來看看是不是Server的問題,或是網路的問題