Java 到安卓?
我如何将 Java 中的这段代码传递到 Android,它在 Eclipse Java 项目中运行良好。
public class GetCode {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://www.sapo.pt/").get();
Elements divs = doc.select("div");
for (Element div : divs)
System.out.println(div.text());
}
}
谁能帮我解决这个问题吗?我在 AndroidManifest.xml 中有互联网访问权限。
How can i pass this code in Java to Android, it works fine in Eclipse Java Project.
public class GetCode {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://www.sapo.pt/").get();
Elements divs = doc.select("div");
for (Element div : divs)
System.out.println(div.text());
}
}
Can anyone help me with this? I have Internet acess in AndroidManifest.xml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,Android应用程序必须扩展Activity。
所以你的代码应该是这样
,并且你不能向它传递参数。如果您想在活动之间传递数据,请使用捆绑包。您必须在 android 项目中编写它,因为它引用了 eclipse 的 android 插件在编译时创建的布局和生成的代码。
如果 div.text() 是 html 文本,您可以使用
它,然后像视图一样使用它,例如在您的提醒对话框广告中,使用
First of all the android applications must extend Activity.
So your code should be
and you can't pass arguments to it. If you want to pass data between activities, use bundles. You must write it within an android project, since it references to layouts and generated code that is created at compile time by eclipse's android plugin.
If div.text() is a html text, you can use
and then use it like a view, for example in your Alert Dialog ad, use