jsoup を使用して URL をクエリしようとすると、次のエラーが発生します: メソッド findViewById(int) は、型に対して未定義です
助言がありますか?(この時点で何が間違っているのか、問題をどのように修正できるのか本当にわかりません)
使用例:
Jsoup パーサーに AsyncTask を使用するには?
ソース:
package com.example.httpgetandroidexample;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class HttpGetAndroidExample<AsyncronoustaskAndroidExample> extends
Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
public class HttpGetAndroidExample<OnCompleteListener> extends
AsyncTask<Void, Void, Void> {
// HERE DECLARE THE VARIABLES YOU USE FOR PARSING
private Element overview = null;
private Element featureList = null;
private Elements features = null;
private Element paragraph = null;
String url = "http://www.sheriff.org/apps/arrest/results.cfm?lname=&fname=";
@Override
protected Void doInBackground(Void... arg0) {
Document doc = null;
try {
doc = Jsoup.connect(url).get();
overview = doc.select("div#object-overview").last();
featureList = doc.select("div.callout-box").last();
features = featureList.select("li");
paragraph = overview.select("p").last();
System.out.println(paragraph.text());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get the paragraph element
// article.setText(paragraph.text()); I comment this out because you
// cannot update ui from non-ui thread, since doInBackground is running
// on background thread.
return null;
}
@Override
protected void onPostExecute(Void result) {
TextView article = (TextView) findViewById(R.id.releaseInfo);
final TextView featuresText = (TextView) findViewById(R.id.features);
for (Element e : features) {
// setText()
}
}
}