[問題] null值無法進入if 判斷式
目前在寫一個程式
是先抓到mysql的再轉換成json字串
但我想寫個判斷式若 值result是null的話 會出現警語
程式是這樣:
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(link);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("1", "Error in http connection " + e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReade
is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("2", "Error converting result " + e.toString());
}
// parse json data
// Log.e("result", result);
if (result==null) {
Toast.makeText(ScheduleActivity.this, R.string.noresult,
Toast.LENGTH_LONG).show();
}
else {
///////////////////////
}
我重Log.e看可以看到我所抓的result 的值是null
但是程式都會進入else裡面而不是在if那邊出現警語
我也試過
if (result.equals(null)) {
}
的寫法還是不行@@
還請高手指點!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.137.72
推
10/08 07:54, , 1F
10/08 07:54, 1F
→
10/08 07:54, , 2F
10/08 07:54, 2F
→
10/08 11:00, , 3F
10/08 11:00, 3F
→
10/08 11:26, , 4F
10/08 11:26, 4F
→
10/08 11:33, , 5F
10/08 11:33, 5F
推
10/08 11:36, , 6F
10/08 11:36, 6F
→
10/08 11:36, , 7F
10/08 11:36, 7F
→
10/08 11:37, , 8F
10/08 11:37, 8F
推
10/08 15:53, , 9F
10/08 15:53, 9F
→
10/08 17:45, , 10F
10/08 17:45, 10F
→
10/08 18:22, , 11F
10/08 18:22, 11F
推
10/08 19:13, , 12F
10/08 19:13, 12F
→
10/08 19:14, , 13F
10/08 19:14, 13F
→
10/08 19:16, , 14F
10/08 19:16, 14F
→
10/08 20:10, , 15F
10/08 20:10, 15F
→
10/08 20:14, , 16F
10/08 20:14, 16F
→
10/08 20:25, , 17F
10/08 20:25, 17F
推
10/08 23:43, , 18F
10/08 23:43, 18F
→
10/09 00:21, , 19F
10/09 00:21, 19F
→
10/10 14:18, , 20F
10/10 14:18, 20F
→
10/10 14:19, , 21F
10/10 14:19, 21F
推
10/11 10:32, , 22F
10/11 10:32, 22F
→
10/11 10:33, , 23F
10/11 10:33, 23F
→
10/11 10:44, , 24F
10/11 10:44, 24F
推
10/11 11:09, , 25F
10/11 11:09, 25F
討論串 (同標題文章)
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章