1

Boilerpipe 是一个基本上从网页中提取主要内容的库。对于新闻网站,由于格式因站点而异,因此提取内容尤其困难。所以我尝试集成锅炉管库 - https://code.google.com/p/boilerpipe/wiki/QuickStart

根据安装指南,我已将以下内容添加到我的 Java 类路径中:boilerpipe-VERSION.jar、nekohtml-1.9.13.jar 和 xerces-2.9.1.jar

我正在尝试使用锅炉管和涉及它的应用程序流程做什么

我有一个列表视图,其中有一个文章列表。我已经设置了一个onItemClickListener,这样当您单击listview上的任何项目时,它会获取特定于该文章的url并使用锅炉管道从该文章中提取文本并开始一个新的活动,它在textview中打印.

问题

一旦我单击列表中的一项,我的应用程序就会崩溃。 一个。我不确定我写的代码是否正确,因为我是初学者。请原谅我。如果不正确,我该如何解决?我感觉这可能是网址的问题。 湾。如果我没有正确安装样板,那么正确的做法是什么

列出活动:

    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

i thing its common problem... u just use AsyncTask. see that....

Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`

don't block main ui use child thread...

于 2013-10-22T12:59:22.567 回答
0

看起来这与 BoilerPlate 没有任何关系,而是您在主线程上进行网络调用的事实。我建议您查看有关此问题的线程

于 2013-10-12T21:23:19.053 回答