-3

I got the next excepcition but I have no idea why. I'm tryiing to get a JSON respones object from a Django server (The Django server works percetly) but i get the next error:

    05-13 19:57:29.069: E/AndroidRuntime(8845): FATAL EXCEPTION: AsyncTask #3
    05-13 19:57:29.069: E/AndroidRuntime(8845): Process: com.example.webservicestemperatura, PID: 8845
    05-13 19:57:29.069: E/AndroidRuntime(8845): java.lang.RuntimeException: An error occured while executing doInBackground()
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.lang.Thread.run(Thread.java:841)
    05-13 19:57:29.069: E/AndroidRuntime(8845): Caused by: java.lang.IllegalArgumentException: Illegal character in scheme at index 0: 192.168.1.68:8000/c_f/4.0
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at java.net.URI.create(URI.java:727)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
    05-13 19:57:29.069: E/AndroidRuntime(8845):     at com.example.webservicestemperatura.MainActivity$sampleService.doInBackground(MainActivity

My code is the next:

class sampleService extends AsyncTask<Boolean, Boolean, Boolean> {

        @Override
        protected Boolean doInBackground(Boolean... params) {
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet del = new HttpGet("192.168.1.68:8000/c_f/4.0");
            del.setHeader("content-type", "application/json");
            try {
                HttpResponse resp = httpClient.execute(del);
                String respStr = EntityUtils.toString(resp.getEntity());
                JSONObject respJSON = new JSONObject(respStr);
                String far = respJSON.getString ("far"); //Check your type data to return in your web service.


                System.out.println("HOLAAAAAAAAAAAAAAAAAAAAAA" + far);
                Log.d("Service", far);
            } catch(Exception ex) {
                Log.e("Service","Error!", ex);
            }
            return null;
        }

If I get the http:// it says "Connection refused": When I use it in a Web Browser it works perfectly And I get the JSON response. But then I get the NEXT ERROR:

05-13 20:10:56.935: E/Service(12445): Error!
05-13 20:10:56.935: E/Service(12445): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.68:8000 refused
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-13 20:10:56.935: E/Service(12445):   at com.example.webservicestemperatura.MainActivity$sampleService.doInBackground(MainActivity.java:53)
05-13 20:10:56.935: E/Service(12445):   at com.example.webservicestemperatura.MainActivity$sampleService.doInBackground(MainActivity.java:1)
05-13 20:10:56.935: E/Service(12445):   at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-13 20:10:56.935: E/Service(12445):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-13 20:10:56.935: E/Service(12445):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-13 20:10:56.935: E/Service(12445):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-13 20:10:56.935: E/Service(12445):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-13 20:10:56.935: E/Service(12445):   at java.lang.Thread.run(Thread.java:841)
05-13 20:10:56.935: E/Service(12445): Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
05-13 20:10:56.935: E/Service(12445):   at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
Cris_Towi
  • 615
  • 1
  • 13
  • 25

2 Answers2

0

Your URI isn't valid, as it is missing the protocol. if you append http:// on the front, it should work correctly

In response to your update, you should learn to read the LogCat properly.

Lines that say Caused by: are ones to look for, as they will usually tell you the root cause of the issue. In this case, a quick google for the exception you posted brings up many Stack Overflow answers that would fix your question.

Community
  • 1
  • 1
panini
  • 2,026
  • 19
  • 21
  • If I use that http:// it says: Connection refused: In the browser it works perfectly and i get the json answer, – Cris_Towi May 14 '14 at 01:12
  • what is the rest of the exception? there are many reasons why the connection might be refused. update the OP – panini May 14 '14 at 01:14
0

Your Url is bad formed, you need defin "htttp://"

http://192.168.1.68:8000/c_f/4.0
Chefes
  • 1,892
  • 18
  • 17