1

Boilerpipe は、基本的に Web ページからメイン コンテンツを抽出するライブラリです。ニュース Web サイトの場合、フォーマットがサイトごとに異なるため、コンテンツを抽出することは特に困難です。だから私はボイラーパイプライブラリを統合しようとしました - https://code.google.com/p/boilerpipe/wiki/QuickStart

インストールガイドに従って、Java クラスパスに以下を追加しました - ボイラーパイプ-VERSION.jar、nekohtml-1.9.13.jar、および xerces-2.9.1.jar

ボイラーパイプとそれを含むアプリケーション フローでやろうとしていること

記事のリストがあるリストビューがあります。listviewの項目のいずれかをクリックすると、その記事に固有のURLを取得し、ボイラーパイプを使用してその記事からテキストを抽出し、テキストビューに印刷される新しいアクティビティを開始するようonItemClickListener設定しました.

問題

リスト内の項目の 1 つをクリックすると、アプリケーションがクラッシュします。 a. 私は初心者なので、書いたコードが正しいかどうかはわかりません。失礼いたします。正しくない場合、どうすれば修正できますか? URLに問題があると思います。 b. ボイラープレートを正しくインストールしていない場合、正しい方法は何ですか

リスト アクティビティ:

    ListView lv = getListView();

    // Launching new screen on Selecting Single ListItem
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Intent in = new Intent(getApplicationContext(), ArticleActivity.class);

            // getting page url
            String page_url = ((TextView) view.findViewById(R.id.page_url)).getText().toString();
            Toast.makeText(getApplicationContext(), page_url, Toast.LENGTH_SHORT).show();
            URL url = null;
            try {
                url = new URL(page_url);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // NOTE: Use ArticleExtractor unless DefaultExtractor gives better results for you
            try {
                String text = null;
                text = ArticleExtractor.INSTANCE.getText(url);
                in.putExtra("text", text);
            } catch (BoilerpipeProcessingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            startActivity(in);              
    });
}

記事のアクティビティ:

public class ArticleActivity extends Activity{

Intent in = getIntent();
String text = in.getStringExtra("text");


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.article_view);

    TextView tv;

    tv = (TextView) findViewById(R.id.page_url);
    tv.setText(text);
    } 
}

article_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<!-- Article Title -->
<TextView android:id="@+id/content_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="10dp"
    android:paddingBottom="8dp"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="#dc6800"/>


</RelativeLayout>

スタックトレース:

USER_COMMENT=null
ANDROID_VERSION=4.1.2
APP_VERSION_NAME=1.0
BRAND=samsung
PHONE_MODEL=GT-N8000
CUSTOM_DATA=
STACK_TRACE=android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
at libcore.net.http.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:130)
at java.net.URLConnection.getContentType(URLConnection.java:326)
at de.l3s.boilerpipe.sax.HTMLFetcher.fetch(HTMLFetcher.java:35)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at com.j.infographx.ListRSSItemsActivity$1.onItemClick(ListRSSItemsActivity.java:94)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
at android.widget.AbsListView$1.run(AbsListView.java:4161)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2

0

これは BoilerPlate とは何の関係もないように見えますが、メイン スレッドでネットワーク呼び出しを行っているという事実です。この問題に関するスレッドをチェックすることをお勧めします。

于 2013-10-12T21:23:19.053 に答える