Hi i need help with a tutorial i tried from ( http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/ ). It's about jsoup but i can't get it to work i only get a lott of errors and stuff. Here is my code:
package com.sigustgebran.appsl; import android.os.Bundle; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import android.app.Activity; import android.view.Menu; import android.widget.TextView; public class MainAct extends Activity { //blog url static final String BLOG_URL = "http://xjaphx.wordpress.com/"; @Override protected void onCreate(Bundle savedInstanceState) { //set layout view super.onCreate(savedInstanceState); setContentView(R.layout.act_main); //process try { ((TextView)findViewById(R.id.tvDisplay)).setText(getBlogStats()); } catch (Exception ex) { ((TextView)findViewById(R.id.tvDisplay)).setText("Error"); } } protected String getBlogStats() throws Exception { String result = ""; //get html document structure Document document = Jsoup.connect(BLOG_URL).get(); //select path Elements nodeBlogStats = document.select("div#blog-stats ul li"); //check results if(nodeBlogStats.size() > 0) { //get value result = nodeBlogStats.get(0).text(); } //return return result; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:layout_gravity="center" android:id="@+id/tvDisplay" /> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sigustgebran.appsl" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.sigustgebran.appsl.MainAct" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> I would be really glad if anyone could help me. Thanks