在android中的ksoap2中的问题

时间:2011-05-10 10:28:29

标签: android web-services

大家好我使用kso​​ap2时遇到了一些问题。

我使用kso​​ap与Web服务进行通信,但它给了我以下错误,请帮助朋友..因为我是Android新手。代码和异常日志cat如下所示。它在我的代码中try块的第一行给出了异常。 请看看并帮助

代码是......

/***********************************************
/PRIVATE DATA MEMBERS
/***********************************************/
 private static EditText userName;
 private static EditText password;
 private static Button submit;
 private static TextView tv;

 private  final String SOAP_ACTION = "action";
 private  final String METHOD_NAME = "login";
 private  final String NAMESPACE = "namspace";
 private  final String URL =  "url";

 private Object resultRequestSOAP = null;



/***********************************************
/OVERRIDDEN METHODS
/***********************************************/

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    userName = (EditText) findViewById(R.id.user);
    password = (EditText) findViewById(R.id.pass);

    tv = (TextView) findViewById(R.id.result);
    submit = (Button)  findViewById(R.id.submit);
    submit.setOnClickListener(this);
    //SoapObject abc = new SoapObject();

}


public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.submit:
        System.out.println("At start");
         SoapObject userRequest=new SoapObject(NAMESPACE, METHOD_NAME);
         String email = userName.getText().toString();
         String pass = password.getText().toString();


         userRequest.addProperty("email", email); // login-account
         userRequest.addProperty("password", pass); // login-password

         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
         request.addProperty("UserLogin", userRequest); // login-account

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         envelope.bodyOut = request;


         AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

         try {


            Object result=envelope.getResponse();


            SoapObject resp=(SoapObject) result;

            System.out.println(resp.getProperty("result"));

            String[] results = (String[])  resultRequestSOAP;

            System.out.println("***********"+results[0]);

            tv.setText( results[0]);


         } catch (Exception aE) {
             System.out.println("in catch");
             aE.printStackTrace();
           }

        System.out.println("M At END");
        break;
    }

}

ERROR LOG CAT IS ..

05-10 16:16:22.861: WARN/System.err(312): java.lang.NullPointerException

05-10 16:16:22.881: WARN/System.err(312):     at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:513)

05-10 16:16:22.881: WARN/System.err(312):     at org.test.FiNear.myFiNear.onClick(myFiNear.java:82)

05-10 16:16:22.891: WARN/System.err(312):     at android.view.View.performClick(View.java:2408)

05-10 16:16:22.891: WARN/System.err(312):     at android.view.View$PerformClick.run(View.java:8816)

05-10 16:16:22.903: WARN/System.err(312):     at android.os.Handler.handleCallback(Handler.java:587)

05-10 16:16:22.903: WARN/System.err(312):     at android.os.Handler.dispatchMessage(Handler.java:92)

05-10 16:16:22.911: WARN/System.err(312):     at android.os.Looper.loop(Looper.java:123)

05-10 16:16:22.911: WARN/System.err(312):     at android.app.ActivityThread.main(ActivityThread.java:4627)

05-10 16:16:22.921: WARN/System.err(312):     at java.lang.reflect.Method.invokeNative(Native Method)

05-10 16:16:22.951: WARN/System.err(312):     at java.lang.reflect.Method.invoke(Method.java:521)

05-10 16:16:22.951: WARN/System.err(312):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

05-10 16:16:22.951: WARN/System.err(312):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

05-10 16:16:22.951: WARN/System.err(312):     at dalvik.system.NativeStart.main(Native Method)
**

1 个答案:

答案 0 :(得分:1)

SoapObject userRequest=new SoapObject(NAMESPACE, METHOD_NAME);
     String email = userName.getText().toString();
     String pass = password.getText().toString();


     userRequest.addProperty("email", email); // login-account
     userRequest.addProperty("password", pass); // login-password
     request.addProperty("UserLogin", userRequest); // login-account
你正在提出两个请求????是一个或如果你和你需要打两个电话