我正在尝试在textview中显示结果,但是我收到错误。代码是:
private class ContentView extends AsyncTask<String,String,String> {
@Override
protected void onPreExecute()
{
mProgressDialog = new ProgressDialog(SingleActivity.this);
mProgressDialog.setTitle("Multiplayer.it");
mProgressDialog.setMessage("Caricamento articoli...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
content = new ArrayList<String>();
}
@Override
protected String doInBackground(String... params) {
try {
//String BLOG_URL_LINKS = links;
Document doc = Jsoup.connect(links).get();
String info = doc.select("div.col-1-1 article p").text();
System.out.println(info);
//info.toString();
} catch (Exception e) {
// In caso di errore
Log.e("ESEMPIO", "ERRORE NEL PARSING");
}
return null;
}
@Override
protected void onPostExecute(String result)
{
articololink = (TextView)findViewById(R.id.content);
articololink.setText(info);
mProgressDialog.dismiss();
}
}
问题是:info cannot be resolved to a variable
。我该怎么办?
答案 0 :(得分:2)
在doInbackground
中声明和初始化信息是doInbackground
的本地信息。
所以在info
doInbackground
@Override
protected String doInBackground(String... params) {
String info=null;
try {
Document doc = Jsoup.connect(links).get();
info = doc.select("div.col-1-1 article p").text();
} catch (Exception e) {
e.printStacktrace();
}
return info;
}
然后在onPostExecute
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
articololink = (TextView)findViewById(R.id.content);
articololink.setText(result);
mProgressDialog.dismiss();
}
请阅读 4个步骤 @
主题http://developer.android.com/reference/android/os/AsyncTask.html