我已经向我的 AsncTask 添加了一个 return 语句,但我仍然收到一个错误,告诉我添加一个。停止此语法错误的唯一代码片段是在 catch 语句之后添加一个 return 语句,但这会适得其反,不能满足程序的需求,而且我无法访问我需要的字符串(我需要检查如果返回的输出流等于真。
代码:
@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();
}
}