我已經向AsncTask添加了一條return語句,但我仍然收到一條錯誤消息,告訴我要添加一條語句。停止這個語法錯誤的唯一代碼片斷是在catch語句之後添加一個return語句,但這是反效果的,並且不能解決程序的需求,我無法訪問我需要的字符串(我需要檢查如果返回OuputStream是等於真正catch語句之前的返回語句
代碼:
@Override
protected Boolean doInBackground(String... userandpass) { //I still get an error telling me to add a return statement
// TODO Auto-generated method stub
URL url;
try {
url = new URL("http://127.0.0.1:1337");
HttpURLConnection URLconnection = (HttpURLConnection) url.openConnection();
URLconnection.setDoOutput(true);
URLconnection.setChunkedStreamingMode(0);
//output stream
OutputStream out = new BufferedOutputStream(URLconnection.getOutputStream());
writestream(out, userandpass);
//buffered server response
InputStream in = new BufferedInputStream(URLconnection.getInputStream());
String result = readstream(in);
Log.e(result, result);
// check we haven't been redirected (Hotel Wifi, for example).
checkrediect(URLconnection, url);
Boolean result_true = checkresult(result);
if(result_true) {
return true;
} else {
return false;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
如果(result_true)返回true;否則返回false;'和return result_true'返回值相同,除去'result_true'上多餘的檢查並在結尾添加'return result_true;' – 2012-08-03 12:43:46
。 – Dahaka 2012-08-03 12:44:44
從第一眼看,我會說,第二個catch-block是缺少return語句的執行路徑。 – jayeff 2012-08-03 12:41:29