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

Matt
  • 295
  • 3
  • 6
  • 17
  • This usually means the app has crashed, you can link to the source code for HttpClient with [Eclipse debugging "source not found"](http://stackoverflow.com/q/1960158/1267661). However this isn't the reason your app crashed, open the LogCat window to see the stack trace. – Sam Apr 06 '13 at 03:30
  • @Sam [here is a screenshot of my logcat](http://i.imgur.com/LDEYkvb.png), but it doesn't seem to provide anything of use? – Matt Apr 06 '13 at 04:09
  • Check the solution in the bottom - http://stackoverflow.com/questions/9161430/using-httpget-on-android. It may work for you. –  May 18 '13 at 12:48

1 Answers1

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

Ajay
  • 1,189
  • 1
  • 12
  • 28
  • I have the jsoup.jar file in my libs folder. Here is my [Package Explorer] (http://i.imgur.com/rbAsItc.png). Also, checked everything in my [Java Build Path](http://i.imgur.com/1zVscCT.png). Still no luck. I'm completely baffled. – Matt Apr 06 '13 at 17:52
  • 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! – Matt Apr 06 '13 at 18:24