android app using jsoup library stopping unexpectedly
<p>I'm a bit new to android and I'm trying to retrieve some data from a website using Jsoup.
Here is the exact code I used in a Java project and it worked. But when I transfer it to Android and change the "println" to "setText()" the app "stops unexpectedly". </p>

<pre><code>package com.ex.myschoolapp;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

Document doc = null;

    try {
        doc = Jsoup.connect("http://moisilonesti.licee.edu.ro/concursuri.php").get();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Elements sElem = doc.select("div#olimpiade table tbody tr th");

    String str = sElem.text();
    TextView stv = (TextView) findViewById(R.id.textView2);
    stv.setText(str);}}
</code></pre>

<p>And here is the LogCat trace:</p>

<pre><code>11-17 17:37:59.145: E/AndroidRuntime(23601): FATAL EXCEPTION: main
11-17 17:37:59.145: E/AndroidRuntime(23601): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.myschoolapp/com.ex.myschoolapp.MainActivity}: java.lang.NullPointerException
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.os.Looper.loop(Looper.java:123)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread.main(ActivityThread.java:3701)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at java.lang.reflect.Method.invokeNative(Native Method)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at java.lang.reflect.Method.invoke(Method.java:507)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at dalvik.system.NativeStart.main(Native Method)
11-17 17:37:59.145: E/AndroidRuntime(23601): Caused by: java.lang.NullPointerException
11-17 17:37:59.145: E/AndroidRuntime(23601):    at com.ex.myschoolapp.MainActivity.onCreate(MainActivity.java:67)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-17 17:37:59.145: E/AndroidRuntime(23601):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
11-17 17:37:59.145: E/AndroidRuntime(23601):    ... 11 more
</code></pre>

<p>I don't know how to use AsyncTask yet but from what I saw in the Jsoup cookbook I shouldn't need any thred to make it work.</p>
