0

i' ve an Webservice that returns this on the browser:

<ArrayOfclients xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebMon.Models">
<clients>
<ClientID>1</ClientID>
<Name>001</Name>
<Telephone i:nil="true"/>
<accumulated>0</accumulated>
<dependant i:nil="true"/>
<description i:nil="true"/>
<id_route_cuadre>1</id_route_cuadre>
<lastName i:nil="true"/>
<status>1</status>
</clients>
<clients>
<ClientID>2</ClientID>
<Name>002</Name>
<Telephone i:nil="true"/>
<accumulated>0</accumulated>
<dependant i:nil="true"/>
<description i:nil="true"/>
<id_route_cuadre>2</id_route_cuadre>
<lastName i:nil="true"/>
<status>1</status>
</clients>
<clients>
<ClientID>3</ClientID>
<Name>003</Name>
<Telephone i:nil="true"/>
<accumulated>0</accumulated>
<dependant i:nil="true"/>
<description i:nil="true"/>
<id_route_cuadre>3</id_route_cuadre>
<lastName i:nil="true"/>
<status>1</status>
</clients>
<clients>
<ClientID>4</ClientID>
<Name>004</Name>
<Telephone i:nil="true"/>
<accumulated>0</accumulated>
<dependant i:nil="true"/>
<description i:nil="true"/>
<id_route_cuadre>4</id_route_cuadre>
<lastName i:nil="true"/>
<status>1</status>
</clients>
<clients>
<ClientID>5</ClientID>
<Name>005</Name>
<Telephone i:nil="true"/>
<accumulated>0</accumulated>
<dependant i:nil="true"/>
<description i:nil="true"/>
<id_route_cuadre>5</id_route_cuadre>
<lastName i:nil="true"/>
<status>1</status>
</clients>
</ArrayOfclients>

But when i try to do the petition on android, give me a nullPointer, even when the petition is on a url.

The code of android:

HttpClient httpclient = new DefaultHttpClient();


    ws = (String) params[0].get(0);
    HttpResponse response = null;
    webparams = (List<NameValuePair>) params[0].get(1);
    HttpGet httppost;
    String connURL="";
    if (ws.indexOf(":")>0){
        connURL +=new ObjConexion().Url()+"/api/"+ws.split(":")[0];
    }else{
        connURL +=new ObjConexion().Url()+"/api/"+ws;
    }

    for (int cont = 0; cont<webparams.size(); cont++){
        if(cont>=1){
            connURL += "&";
        }
        if(cont==0){
            connURL +="?";
        }
        connURL+=webparams.get(cont).getName()+"="+webparams.get(cont).getValue();
    }

    httppost = new HttpGet(connURL);
    try {
        // Add your data

        // Execute HTTP Post Request
        response = httpclient.execute(httppost);
        if(response == null){
            Log.wtf("Mistake:", "El valor es null");
        }


        try {
            cookies = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();
        } catch (Exception e) {
        }
        return response;


    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        Log.e("Error:", e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.e("Error:", e.getMessage());
    }
    return response; 

My stacktrace log:

12-22 23:57:00.464: I/System.out(6424): httpget:http://x.x.x.x:x/api/clients?id=43
12-22 23:57:00.465: I/System.out(6424): http://x.x.x.x:x/api/clients?id=43
12-22 23:57:00.467: V/PhoneWindow(6424): DecorView setVisiblity: visibility = 4
12-22 23:57:00.472: I/System.out(6424): [socket][1] connection /209.126.71.80:8091;LocalPort=49434(0)
12-22 23:57:00.473: I/System.out(6424): [CDS]connect[/209.126.71.80:8091] tm:90
12-22 23:57:00.474: D/Posix(6424): [Posix_connect Debug]Process charge.system :8091 
12-22 23:57:00.474: V/PhoneWindow(6424): DecorView setVisiblity: visibility = 0
12-22 23:57:00.476: V/InputMethodManager(6424): focusOut: android.widget.EditText{41306088 VFED..CL .F...... 50,149-268,189 #7f08000d app:id/username} mServedView=android.widget.EditText{41306088 VFED..CL .F...... 50,149-268,189 #7f08000d app:id/username} winFocus=false
12-22 23:57:00.491: V/InputMethodManager(6424): Not IME target window, ignoring
12-22 23:57:00.515: I/(6424): [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
12-22 23:57:00.515: I/(6424): [Mali]max_allowed_dequeued_buffers=3
12-22 23:57:00.526: I/SurfaceTextureClient(6424): [STC::queueBuffer] (this:0x51934918) fps:2.16, dur:1388.43, max:521.31, min:398.98
12-22 23:57:00.553: V/InputMethodManager(6424): onWindowFocus: com.android.internal.policy.impl.PhoneWindow$DecorView{412f6118 VFE..... RF....I. 0,0-320,359} softInputMode=272 first=true flags=#1810100
12-22 23:57:00.553: D/InputMethodManager(6424): deactivate the inputconnection in ControlledInputConnectionWrapper.
12-22 23:57:00.553: V/InputMethodManager(6424): START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{412f6118 VFE..... RF....I. 0,0-320,359} ic=null tba=android.view.inputmethod.EditorInfo@412ef2c0 controlFlags=#105
12-22 23:57:00.589: V/InputMethodManager(6424): Starting input: Bind result=InputBindResult{com.android.internal.view.IInputMethodSession$Stub$Proxy@412ef430 com.android.inputmethod.latin/.LatinIME #117}
12-22 23:57:00.595: I/System.out(6424): [socket][/192.168.0.5:49434] connected
12-22 23:57:00.595: I/System.out(6424): [CDS]rx timeout:0
12-22 23:57:00.597: I/System.out(6424): >doSendRequest
12-22 23:57:00.598: I/System.out(6424): <doSendRequest
12-22 23:57:00.650: D/OpenGLRenderer(6424): Flushing caches (mode 0)
12-22 23:57:00.793: D/AndroidRuntime(6424): Shutting down VM
12-22 23:57:00.793: W/dalvikvm(6424): threadid=1: thread exiting with uncaught exception (group=0x40ef99a8)
12-22 23:57:00.795: E/AndroidRuntime(6424): FATAL EXCEPTION: main
12-22 23:57:00.795: E/AndroidRuntime(6424): java.lang.NullPointerException
12-22 23:57:00.795: E/AndroidRuntime(6424):     at charge.system.genConServer.onPostExecute(GenConn.java:94)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at charge.system.genConServer.onPostExecute(GenConn.java:1)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.os.AsyncTask.finish(AsyncTask.java:631)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.os.Handler.dispatchMessage(Handler.java:107)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.os.Looper.loop(Looper.java:194)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at android.app.ActivityThread.main(ActivityThread.java:5371)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at java.lang.reflect.Method.invokeNative(Native Method)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at java.lang.reflect.Method.invoke(Method.java:525)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-22 23:57:00.795: E/AndroidRuntime(6424):     at dalvik.system.NativeStart.main(Native Method)

I don't understand why is nullPointer on that area, and have data on the browser.

2
  • Can you please post your stacktrace logs Commented Dec 23, 2014 at 4:28
  • As mentioned in your stacktrace, NPE is occurring at charge.system.genConServer.onPostExecute(GenConn.java:94). You can debug your code and find out which object is null because of which you are getting NPE. Commented Dec 23, 2014 at 4:53

1 Answer 1

1

U have set your HttpResponse to null i think this is causing the null pointer exception. Try this, Instead of setting HttpResponse response=null

HttpResponse response = httpclient.execute(httppost);
Sign up to request clarification or add additional context in comments.

1 Comment

The problem was with the delegate, that was null. But thanks for the answer!

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.