Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

FATAL EXCEPTION: AsyncTask #3 in JSON Response for Android

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

http://192.168.1.68:8000/c_f/4.0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...