java.lang.NullPointerException:println需要一条消息soap

时间:2013-01-29 09:47:47

标签: java android soap httptransportse

我的源代码,

private static final String URL = "http://footballpool.dataaccess.eu/data/info.wso";
private static final String NAME_SPACE = "http://footballpool.dataaccess.eu";
private static final String METHODE_NAME = "TopGoalScorers";
private static final String SOAP_ACTION = NAME_SPACE + "/" + METHODE_NAME;


SoapObject request = new SoapObject(NAME_SPACE, METHODE_NAME);

    request.addProperty("iTopN", 10);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

    envelope.setOutputSoapObject(request);

    HttpTransportSE transporte = new HttpTransportSE(URL);


    SoapObject soapObject = null;
    try {
        transporte.call("http://footballpool.dataaccess.eu/data/info.wso/TopGoalScorers", envelope);

        soapObject = (SoapObject) envelope.getResponse();

    } catch (Exception e) {
        Log.e("Soap", e.getMessage());
    }

我给出了这个错误:

> 01-29 10:44:17.877: E/AndroidRuntime(10704): FATAL EXCEPTION: main
01-29 10:44:17.877: E/AndroidRuntime(10704): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.serviosweb/com.android.serviosweb.MainActivity}: java.lang.NullPointerException: println needs a message
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.os.Looper.loop(Looper.java:137)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at java.lang.reflect.Method.invokeNative(Native Method)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at java.lang.reflect.Method.invoke(Method.java:511)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at dalvik.system.NativeStart.main(Native Method)
01-29 10:44:17.877: E/AndroidRuntime(10704): Caused by: java.lang.NullPointerException: println needs a message
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.util.Log.println_native(Native Method)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.util.Log.e(Log.java:231)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at com.android.serviosweb.MainActivity.onCreate(MainActivity.java:44)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.Activity.performCreate(Activity.java:5104)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-29 10:44:17.877: E/AndroidRuntime(10704):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-29 10:44:17.877: E/AndroidRuntime(10704):    ... 11 more

任何人请帮助我

4 个答案:

答案 0 :(得分:3)

在catch语句中使用:

String errorMessage = (ex.getMessage()==null)?"Message is empty":ex.getMessage();
Log.e("Message:",errorMessage );  

答案 1 :(得分:0)

在捕获中,使用:

String err = (ex.getMessage()==null)?"SD Card failed":ex.getMessage();
Log.e("sdcard-err2:",err);  

答案 2 :(得分:0)

你的问题很简单。您的try Block中会抛出异常。 Catch-Block现在尝试通过将Exception消息打印到Log来处理这些异常。不太可能没有设置要打印的消息,并且您的Logger(sys.out.print)无法打印任何内容(空值)。

只要您想打印StackTrace,就像Mohamed_AbdAllah建议的那样。您需要将StackTrace作为String Guava,Apache Commons具有用于此目的的方法。一个简单的构建方式是:

StackTraceElement[] stack = e.getStackTrace();
StringTrace = "";
for(StackTraceElement line : stack)
{
   Trace += line.toString();
}

    Log.e("Soap",Trace);

答案 3 :(得分:0)

使用此代码:(例如)

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo username = new PropertyInfo();
        username.setName("username");
        username.setValue("google");
        username.setType(String.class);
        username.setNamespace(NAMESPACE);
        request.addProperty(username);