views:

245

answers:

1

My web service should be returning an integer, but every time i run the code i get the NullPointerException error. Any ideas or help would be very appreciated

Here's my code:

public class CGCountTest extends Activity {

TextView testTV;

private static final String NAMESPACE = "http://passport-america.com/webservices/";
private static final String URL = "http://localhost:11746/Service1.asmx";
private static final String SOAP_ACTION = "http://www.passport-america.com/webservices/getCGCount";
private static final String METHOD_NAME = "getCGCount";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.soap_test);

      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope =
            new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                java.lang.Integer result = (Integer)envelope.getResponse();
                TextView testTV = (TextView)findViewById(R.id.testTV);
                result.toString();
                testTV.setText(result);
            }
            catch(Exception e)
            {
                testTV.setText(e.getMessage());
            }
}

here's the logcat

06-02 15:13:36.557: WARN/dalvikvm(326): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 06-02 15:13:36.557: ERROR/AndroidRuntime(326): Uncaught handler: thread main exiting due to uncaught exception 06-02 15:13:36.876: ERROR/AndroidRuntime(326): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pa.passammain/com.pa.passammain.CGCountTest}: java.lang.NullPointerException 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.access$2100(ActivityThread.java:116) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.os.Looper.loop(Looper.java:123) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.main(ActivityThread.java:4203) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at java.lang.reflect.Method.invokeNative(Native Method) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at java.lang.reflect.Method.invoke(Method.java:521) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at dalvik.system.NativeStart.main(Native Method) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): Caused by: java.lang.NullPointerException 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.pa.passammain.CGCountTest.onCreate(CGCountTest.java:46) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): ... 11 more

i think my url string may be the problem, but i've tried using my ip with no luck

A: 

It's not your URL string (it may not be correct but it is a valid string), one of the function calls that you are using has null as one of the input parameters. Most likely, it's because you tried to do something that returned null, and then used that value in another method call.

I don't know what you have on line 326 of your code, but I bet one of the objects there is null, so I'd start checking that first.

If you want to paste line 326, I'll be able to help further.

Robert Greiner
Thank you for such a quick response! The funny thing is, in that specific class file i only have 49 lines of code. Am i missing something? I am sorta new to android development so bare with me if you can.
benjamin schultz
326 is the process ID, not a line number. CGCountTest.java:46 is what's indicated by the stack trace.
Christopher