1

I am trying to retrieve a website's html code and parse it to get the site's text. For some reason the class I have below runs fine when I comment out the jsoup library part of the code, but otherwise I get this weird error "source code not found", and the debug section does not hit any of the breakpoints. Not even those before any jsoup code. It jumps right to the error as soon as I hit the button on the emulator. I have the jsoup jar file added to my eclipse project as an external JAR in my java build path. What am I doing wrong?

BTW: I have jsoup 1.6.2

public class AndroidActivity extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final EditText eText = (EditText) findViewById(R.id.address);
        final TextView tView = (TextView) findViewById(R.id.pagetext);
        // TODO Auto-generated method stub

        class TareaAsincrona extends AsyncTask<String, Void ,String>
        {
            @Override
            protected void onPreExecute()
            {
            }
            @Override
            protected void onPostExecute(String X)
            {
            }
            @Override
            protected String doInBackground(String... urls) 
            {
                try
                {
                    // Perform action on click
                    URL url = new URL(eText.getText().toString());
                    URLConnection conn = url.openConnection();
                    // Get the response
                    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    String line = "";
                    String Codigo_Fuente ="";
                    while ((line = rd.readLine()) != null) 
                    {
                        Codigo_Fuente= Codigo_Fuente + line;
                        //Codigo_Fuente.add(line);//android.text.Html.fromHtml(line).toString());
                    }
                    Document doc = Jsoup.parse(Codigo_Fuente);
                    return doc.body().text();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    return null;
                }
            }
        }

        final Button button = (Button) findViewById(R.id.ButtonGo);
        button.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View arg0) 
            {
                new TareaAsincrona().execute();
            }
        });
    }
}
dave.c
  • 10,910
  • 5
  • 39
  • 62
user1181589
  • 153
  • 1
  • 10

1 Answers1

1

Did you add the library to the "libs" folder too?

PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53