为什么Exception在android中为null

时间:2013-08-21 04:00:15

标签: android eclipse

httpTransport.call 这行代码有例外,但ex为null

private static String CallServiceMethod(String methodName,String Json) throws Exception
 {      
Object response = null;
        try
        {       
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,methodName);

        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName("Json");
        propertyInfo.setValue(Json);
        propertyInfo.setType(String.class);
        request.addProperty(propertyInfo);

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

        envelope.setOutputSoapObject(request);
        HttpTransportSE httpTransport = new HttpTransportSE(SystemConfiguration.ServiceUrl);        
        httpTransport.call(WSDL_TARGET_NAMESPACE + methodName, envelope); //Error
        response = envelope.getResponse();
        }
        catch (Exception ex)
        {
            //TODO:Log
            String x = ex.getMessage(); //why ex is null???
        }
        return response.toString();

    }  

2 个答案:

答案 0 :(得分:0)

尝试使用像

这样的东西
catch(Exception ex)
{
    Toast.makeText(this, "Exception ex1  = " + ex.toString(), Toast.LENGTH_LONG).show();
     Log.d(TAG, "Exception ex1  = " + ex.toString());
     return  "Exception ex1  = " + ex.toString();
}
  `

答案 1 :(得分:0)

有时收到的异常可能为空... 所以在通过日志值打印时

Log.d(TAG, "add some string here" + ex.toString());

避免空指针异常