我已经向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