gpt4 book ai didi

java - 在 Android 中使用锅炉管

转载 作者:行者123 更新时间:2023-12-01 04:19:32 25 4
gpt4 key购买 nike

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

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

我想用锅炉管道做什么以及涉及它的应用程序流程

我有一个 ListView ,其中有文章列表。我设置了一个 onItemClickListener,这样当您单击 listview 上的任何项目时,它就会获取特定于该文章的 url并使用boilerpipe从该文章中提取文本,并启动一个新 Activity ,并将其打印在textview中。

问题

单击列表中的一项后,我的应用程序崩溃了。a. 我不确定我编写的代码是否正确,因为我是初学者。请原谅。如果不正确,我该如何修复?我感觉可能是网址有问题。b.如果我没有正确安装样板,正确的安装方法是什么

列出 Activity :

    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);
});
}

文章 Activity :

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)

最佳答案

看起来这与 BoilerPlate 没有任何关系,而是您在主线程上进行网络调用的事实。我建议您查看this thread regarding the problem .

关于java - 在 Android 中使用锅炉管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19088702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com