Note that there are some explanatory texts on larger screens.

plurals
  1. POApp works in Emulator, but not on a real device
    text
    copied!<p>Currently following this tutorial <a href="http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/" rel="nofollow">Android XML Adventure – Parsing HTML using JSoup</a>, app works in Emulator, but display Error in TextView on device.</p> <p>I have copy and paste jsoup-1.7.2.jar into libs, set <code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;</code> in AndroidManifest.xml and set TextView <code>android:id="@+id/tv"</code> . And this is what my <a href="http://s24.postimg.org/6l1vveiud/eclipse.png" rel="nofollow">Project Explorer</a> looks like.</p> <p>Here is the JsoupActivity.java</p> <pre><code>package com.jsoupstudyactivity; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.view.Menu; public class JSoupActivity extends Activity { // blog url static final String BLOG_URL = "http://xjaphx.wordpress.com/"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // process try { ((TextView)findViewById(R.id.tv)).setText(getBlogStats()); } catch (Exception ex) { ((TextView)findViewById(R.id.tv)).setText("Error"); } } protected String getBlogStats() throws Exception { String result = ""; // get html document structure Document document = Jsoup.connect(BLOG_URL).get(); // selector query Elements nodeBlogStats = document.select("div#blog-stats-2 ul li"); // check results if(nodeBlogStats.size() &gt; 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.jsoup, menu); return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload