2010-12-17 51 views
0

我已經加入庫 「ksoap2,機器人組裝-2.4-JAR-與-dependencies.jar」 但我得到下面的錯誤是:KXmlParser.require(KXmlParser.java而在Java訪問SOAP Web服務

Exception in thread "main" java.lang.NullPointerException at org.kxml2.io.KXmlParser.require(KXmlParser.java:1353) at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127) at org.ksoap2.transport.Transport.parseResponse(Transport.java:63) at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100) 


    private void getData() 
    { 
    String METHOD_NAME = "schedule.setschedule"; 

     String SOAP_ACTION = "urn:schedule#setschedule"; 

     String NAMESPACE = "urn:schedule"; 

     String URL = "http://96.30.19.40:8080/server.php?wsdl"; 

     try { 
      SoapObject request=soap(METHOD_NAME,SOAP_ACTION,NAMESPACE,URL); 
      System.out.println("suceess"); 
      System.out.println(request.toString()); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      System.out.println("fail1"); 
      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      System.out.println("fail2"); 
     } 
} 

public static SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request 
     request.addProperty("iTopN", "5"); //variable name, value. I got the variable name, from the wsdl file! 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope 

     envelope.setOutputSoapObject(request); //prepare request 

     HttpTransport httpTransport = new HttpTransport(URL); 

     httpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump) 

     httpTransport.call(SOAP_ACTION, envelope); //send request 

     SoapObject result=(SoapObject)envelope.getResponse(); //get response 
     return result; 
    } 
+0

你在你的CLASSPATH中是否有包含javax/microedition/io/Connector的jar文件? – CoolBeans 2010-12-17 06:54:30

+0

教你請給我jar的路徑,以便iu可以下載並添加到classpath中。我無法得到相同的結果。 – Maneesh 2010-12-17 07:02:11

回答

0

您可能沒有正確ksoap2

+0

我已經添加了庫「ksoap2-android-assembly-2.4-jar-with-dependencies.jar」,但現在我得到下面的錯誤:線程「主」java.lang.NullPointerException中的異常 \t at org.kxml2.io .KXmlParser.require(KXmlParser.java:1353) \t在org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127) \t在org.ksoap2.transport.Transport.parseResponse(Transport.java:63) \t在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100) – Maneesh 2010-12-17 07:00:02

+0

添加這個jar文件kxml2-min-2.3.0.jar – Enrique 2010-12-17 07:06:08

+0

我已經添加了jar kxml2-min-2.3.0.jar,但仍然得到相同的錯誤,不要爲什麼它沒有拿着罐子 – Maneesh 2010-12-17 07:39:07