【问题标题】:androidHttpTransport.call(...,...) throwing null exception, when printing using ex.getMessage()androidHttpTransport.call(...,...) 在使用 ex.getMessage() 打印时抛出空异常
【发布时间】:2012-01-19 10:58:34
【问题描述】:

我从使用eclipse开发的andriod应用程序调用webservice, 但是调用时出现异常 androidHttpTransport.call(SOAP_ACTION, 信封);

ex.getMessage() 打印“null”异常消息

在我指定的清单文件中

 <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

以下是完整代码

///////////////////
public class Yasir1Activity extends Activity {
    TextView tv;  



            private final String NAMESPACE = "http://www.webserviceX.NET/"; 
            private final String URL = "http://www.webservicex.net/ConvertWeight.asmx"; 
            private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight"; 
            private final String METHOD_NAME = "ConvertWeight"; 
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {  
                super.onCreate(savedInstanceState);  
                setContentView(R.layout.main);  
                tv=(TextView)findViewById(R.id.txt); 

            String msg="";
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
            String weight = "3700"; 
            String fromUnit = "Grams"; 
            String toUnit = "Kilograms"; 

            PropertyInfo weightProp =new PropertyInfo(); 
            weightProp.setName("Weight"); 
            weightProp.setValue(weight); 
            weightProp.setType(double.class); 
            request.addProperty(weightProp); 

            PropertyInfo fromProp =new PropertyInfo(); 
            fromProp.setName("FromUnit"); 
            fromProp.setValue(fromUnit); 
            fromProp.setType(String.class); 
            request.addProperty(fromProp); 

            PropertyInfo toProp =new PropertyInfo(); 
            toProp.setName("ToUnit"); 
            toProp.setValue(toUnit); 
            toProp.setType(String.class); 
            request.addProperty(toProp); 

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

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
            try 
            { 
                msg="before call";
                androidHttpTransport.call(SOAP_ACTION, envelope); //throwing exception
                msg+="call success";


                SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
                //Log.i("myApp", response.toString()); 
                //TextView tv = new TextView(this); 
                msg+=response.toString();
                tv.setText(response.toString());//weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit); 

            } 
            catch(SocketException ex)
               {
                 msg+="Error on soapPrimitiveData() " + ex.getMessage();
                   ex.printStackTrace();
               }
            catch (Exception e) 
            { 
                e.printStackTrace(); 
                msg += "Exception " +e.getMessage(); //"Exception null" is printing
            }


            tv.setText( msg);

            } 
            }

【问题讨论】:

    标签: android web-services soap nullpointerexception


    【解决方案1】:

    我遇到了同样的问题。我得到一个空异常,因为我在主线程中尝试。 Honeycomb SDK 或更高版本的问题。 http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

    解决方案,在新线程中运行进程。

    您好!

    【讨论】:

      【解决方案2】:

      您应该看到这个Double with ksoap2 on Android? 以将 Double 属性添加到您在 ksoap2 中的 soap 请求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-26
        • 2013-05-24
        • 2013-08-08
        • 2016-09-26
        • 1970-01-01
        • 2017-09-02
        • 2012-09-09
        • 2015-09-25
        相关资源
        最近更新 更多