0

我知道已经有很多与此问题相关的问题,但我仍然无法找出它为什么给出 NPE。

package com.example.soapweb;
import java.util.HashMap;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class DotNetWebService extends Activity {

    private String NAMESPACE = "http://eworldsolutions.in/";
    private String METHOD_NAME="SupervisorDataToSAM_Authenticate" ;
    //String SOAP_ACTION;
    String URL="http://192.168.1.222/CFMSMobileService/Service.asmx";

    private static String SOAP_ACTION = "http://eworldsolutions.in/SupervisorDataToSAM_Authenticate";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dotnet);

        final Button webserviceCallButton = (Button) findViewById(R.id.btn);
        final TextView webserviceResponse = (TextView) findViewById(R.id.txtv_id);

        webserviceCallButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                 try {


                    String strServerResponse=  new GetResult().execute().get();

                 // lblResult1.setText(resultsRequestSOAP.toString());
                  } catch (Exception e) 
                  {

                  System.out.println("Error"+e);
                 }
            }
        });

    }



private class GetResult extends AsyncTask<String, Void, String> {


        ProgressDialog dialog=new ProgressDialog(getApplicationContext());
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub

             //dialog= new ProgressDialog();

            this.dialog.setMessage("Please wait...");
            this.dialog.show();

            super.onPreExecute();
        }



        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub


            Object response=null;
             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


              PropertyInfo pi1 = new PropertyInfo();
              pi1.setName("LoginID");
              pi1.setValue("ffd");
              pi1.setType(String.class);

              PropertyInfo pi2 = new PropertyInfo();
              pi1.setName("Password");
              pi1.setValue("Hhjhjh");
              pi1.setType(String.class);

              request.addProperty(pi1);
              request.addProperty(pi2);

              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
              envelope.dotNet=true;

              try
              {
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


              androidHttpTransport.call(SOAP_ACTION,envelope);
              response =  envelope.getResponse().toString();

              }

              catch(Exception e)
              {

              }


             return response.toString();
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub

             dialog.dismiss();
            super.onPostExecute(result);
        }


    }


}

这是 Logcat 结果:

02-28 05:34:43.957: E/AndroidRuntime(1711): FATAL EXCEPTION: AsyncTask #1
02-28 05:34:43.957: E/AndroidRuntime(1711): Process: com.example.soapweb, PID: 1711
02-28 05:34:43.957: E/AndroidRuntime(1711): java.lang.RuntimeException: An error occured while executing doInBackground()
02-28 05:34:43.957: E/AndroidRuntime(1711):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.lang.Thread.run(Thread.java:841)
02-28 05:34:43.957: E/AndroidRuntime(1711): Caused by: java.lang.NullPointerException
02-28 05:34:43.957: E/AndroidRuntime(1711):     at com.example.soapweb.DotNetWebService$GetResult.doInBackground(DotNetWebService.java:173)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at com.example.soapweb.DotNetWebService$GetResult.doInBackground(DotNetWebService.java:1)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-28 05:34:43.957: E/AndroidRuntime(1711):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
4

1 回答 1

0

愚蠢的错误。相同的属性添加了两次:

PropertyInfo pi2 = new PropertyInfo();
              pi2.setName("Password");
              pi2.setValue("Hhjhjh");
              pi2.setType(String.class);

多谢你们。

于 2014-02-28T12:13:40.603 回答