Java代码:
package com.piyush.bankai;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HomeParse extends Activity {
static final String BLOG_URL = "http://www.google.com/";
Document doc=null;
String linkText=null;
String linkHref=null;
//TextView a;
@Override
public void onCreate(Bundle savedInstanceState) {
// set layout view
super.onCreate(savedInstanceState);
setContentView(R.layout.homeparse);
try {
doc = Jsoup.connect("http://en.wikipedia.org/").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Elements divs = doc.select("#mp-itn b a");
for (Element div : divs) {
linkHref = div.attr("href");
linkText = div.text();
}
try {
((TextView)findViewById(R.id.tv1)).setText(linkHref);
} catch (Exception ex) {
((TextView)findViewById(R.id.tv1)).setText("kalal");
}
for (Element div : divs)
System.out.println(div.text());
}
}
xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id="@+id/tv1"
/>
</LinearLayout>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.piyush.bankai"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Flip"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Queries"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.QUERIES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Test"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".HomeParse"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.HOMEPARSE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
运行此项目后,我在控制台中看到的只是安装成功!和完成。就是这样,输出没有显示在android设备中。请帮我调试这个错误。我尝试创建其他项目,它们似乎运行良好。