【发布时间】:2014-06-17 08:25:19
【问题描述】:
我是 Java 新手,我试图在函数末尾返回一个已定义的字符串变量,但 eclipse 一直说它无法解析为变量,并希望我定义它。可能是因为我在 Try{} 括号内定义了变量,但我还能怎么做呢?
public class readtextfile extends AsyncTask<String, Integer, String>{
private TextView description;
public readtextfile(TextView descriptionTextView){
this.description = descriptionTextView;
}
@Override
protected String doInBackground(String... params) {
try {
URL url = new URL("http://example.com/description1.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
String result = "";
while ((line = in.readLine()) != null) {
//get lines
result+=line;
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
protected void onProgressUpdate() {
//called when the background task makes any progress
}
protected void onPreExecute() {
//called before doInBackground() is started
}
@Override
protected void onPostExecute(String result) {
this.description.setText(result);
}
}
【问题讨论】:
标签: java function variables return