-1
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設備上。請幫我調試這個bug。我曾嘗試創建其他項目,他們似乎運行良好。
非常感謝你much.It的工作。 – SeasonalShot 2013-03-07 16:37:29