0

I've been stuck on this issue for a long time and can't seem to find a fix. I have a method where I want to retrieve the HTML source of a website, but every time I run the client.execute step, Eclipse outputs "Source not found". I can hit a breakpoint prior to that step and whether I try to "step over" that line or just hit "go" I still receive "Source not found". This is my method

private void getQuestions()
{
    try 
    {

        URI url = null;
        try 
        {
            url = new URI("http://google.com");
        }
        catch (URISyntaxException e)
        {
            e.printStackTrace();
        }

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(url);

        // THIS LINE CAUSES SOURCE NOT FOUND
        HttpResponse response = client.execute(request);

        System.out.println("HttpResponse received");

    }
    catch (ClientProtocolException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

In my AndroidManifest.xml file I've also added the following prior to my tags

 <uses-sdk
    android:minSdkVersion="13"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>

I've found some people with similar problems and tried their fixes with no success. I've added my application name to my source path and placed it above Default.

source

I've also moved my Application to be bottom of my build paths

build path

I am running Eclipse IDE for Java Developers

Version: Juno Service Release 1

3

1 Answer 1

0

I have created one demo, and its working fine in mine.. please check it, i think it might help you..

URI url = null;
        try 
        {
            url = new URI("http://www.google.com");

            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(url);

            HttpResponse response = client.execute(request);

            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = "";
            StringBuilder total = new StringBuilder();
            try 
            {
                while ((line = rd.readLine()) != null) 
                { 
                    total.append(line);
                }
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
            Log.w("Html",total.toString());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

and i am using this in my Manifest file.

<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />

and i think you should put your "jsoup-1.7.2.jar" file in libs directory and add jar in project from this libs directory. and just select checkbox to "check (true)" of your jar in Java Build Path dialog. ( It's not necessary but it should checked). like..

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I have the jsoup.jar file in my libs folder. Here is my [Package Explorer] (i.imgur.com/rbAsItc.png). Also, checked everything in my Java Build Path. Still no luck. I'm completely baffled.
Ah! I'm finally catching an Exception "android.os.NetworkOnMainThreadException" after adding catch (Exception e) to my code. I haven't figured out why I have an exception yet, but this is much much better!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.