尝试调用Web服务时出现空指针异常

时间:2014-07-31 04:49:06

标签: android web-services nullpointerexception android-ksoap2

我正在尝试创建一个调用Web服务的应用程序,但我不断收到java.lang.NullPointerException。我之前使用过类似的代码用于另一个网络服务,但没有提出问题,所以我无法弄清楚我做错了什么

我的代码是:

a1=(EditText)findViewById(R.id.code);
a2=(EditText)findViewById(R.id.pwd);
String ac=a1.getText().toString();
String bn=a2.getText().toString();

String SOAP_ACTION = "http://www.airindia.in/getFFP";
String OPERATION_NAME = "getFFP";
String WSDL_TARGET_NAMESPACE = "http://www.airindia.in/";
String SOAP_ADDRESS = "http:// 203.199.104.203/ffp-details.asmx";
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
request.addProperty("membercode",ac);
request.addProperty("pwd",bn);
request.addProperty("pass_key", "URFFPDetails@AirIndia");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
    httpTransport.debug = true;
    httpTransport.call(SOAP_ACTION, envelope);
    String ss = httpTransport.responseDump;
    TextView l1 = (TextView) findViewById(R.id.result);
    l1.setText(ss);
    l1.setVisibility(View.VISIBLE); 
}
catch (Exception exception) {
    exception.printStackTrace();   
} 

logcat引发的异常是:

07-31 10:04:23.029: W/System.err(6944): java.lang.NullPointerException
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpConnection$Address.hashCode(HttpConnection.java:343)
07-31 10:04:23.029: W/System.err(6944):     at java.util.HashMap.get(HashMap.java:298)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:67)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
07-31 10:04:23.029: W/System.err(6944):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
07-31 10:04:23.039: W/System.err(6944):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
07-31 10:04:23.039: W/System.err(6944):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:152)
07-31 10:04:23.039: W/System.err(6944):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
07-31 10:04:23.039: W/System.err(6944):     at com.example.ffp.MainActivity.go(MainActivity.java:120)
07-31 10:04:23.039: W/System.err(6944):     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 10:04:23.039: W/System.err(6944):     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 10:04:23.039: W/System.err(6944):     at android.view.View$1.onClick(View.java:3058)
07-31 10:04:23.039: W/System.err(6944):     at android.view.View.performClick(View.java:3534)
07-31 10:04:23.039: W/System.err(6944):     at android.view.View$PerformClick.run(View.java:14263)
07-31 10:04:23.039: W/System.err(6944):     at android.os.Handler.handleCallback(Handler.java:605)
07-31 10:04:23.039: W/System.err(6944):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 10:04:23.039: W/System.err(6944):     at android.os.Looper.loop(Looper.java:137)
07-31 10:04:23.039: W/System.err(6944):     at android.app.ActivityThread.main(ActivityThread.java:4441)
07-31 10:04:23.039: W/System.err(6944):     at java.lang.reflect.Method.invokeNative(Native Method)
07-31 10:04:23.039: W/System.err(6944):     at java.lang.reflect.Method.invoke(Method.java:511)
07-31 10:04:23.049: W/System.err(6944):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-31 10:04:23.049: W/System.err(6944):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-31 10:04:23.049: W/System.err(6944):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案