【发布时间】:2012-07-02 05:15:25
【问题描述】:
我在我的 xml 文件中设置了权限,据我所知,我正在一个新线程中运行连接。这个程序非常基础,我什么也得不到。
我想要程序做的就是从网站上读取所有的 HTML 代码。
我的主要课程在这里:
package com.example.beem;
import java.util.concurrent.Callable;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
public class Beamer extends Activity {
Button checkbutton;
TextView title;
TextView status;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beamer);
checkbutton = (Button) findViewById(R.id.checker);
title = (TextView) findViewById(R.id.title);
status = (TextView) findViewById(R.id.status);
checkbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
status.setText("*click*");
status.setText("loading");
Callable <String> call = new threadWebRead();
try {
String dub = call.call();
status.setText(dub);
} catch(Exception e) {}
}
});
}
}
我的实现可调用的类在这里:
package com.example.beem;
import java.util.concurrent.Callable;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.util.Log;
public class threadWebRead implements Callable{
public String call() throws Exception {
// TODO Auto-generated method stub
Document doc = 'Jsoup.connect("http://www.spring8.or.jp/ext/ja/status/text.html").get();
String title = doc.title();
return title;
}
}
我只是想先看看Jsoup 是否会起作用,然后我才弄清楚如何阅读所有 HTML,但似乎什么也没发生。事实上,我在这里尝试了很多从网站读取 HTML 的示例,但它们似乎都不起作用!有人说Jsoup 让事情变得更容易,但我没有运气。
编辑,事实上,我认为它实际上并没有成功地在线程中执行连接线。
非常感谢您的帮助。
Logs 来自应用程序。
【问题讨论】:
-
我一直在胡闹,似乎即使我正在使用新线程阅读网站,但仍有一些东西违反了 UI 线程。
-
Java 类型名称应以大写字母开头。