2014-02-28 110 views
0

我知道已經有很多問題涉及這個問題,但我仍然無法找出爲什麼它給NPE。在Android中調用肥皂web服務給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) 
+0

您需要發佈的堆棧跟蹤,並指示該行導致錯誤時拋出 – Raghunandan

+0

@Raghunandan現在,它的捐贈:android.view.WindowManager $ BadTokenException:無法添加窗口 - 令牌null不是一個應用程序 –

+0

張貼堆棧跟蹤,或者你無法找到幫助 – Raghunandan

回答

0

愚蠢的錯誤。相同的財產增加了兩次:

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

謝謝你們。