我創建了java soap web服務並嘗試將其與android app連接。我創建了一個表im數據庫作爲登錄並給出fields.The問題是我的android應用程序代碼不connectctimg並獲取數據。它顯示沒有錯誤的xml登錄頁面os加載,但在按鈕沒有動作。如果我檢查logcat沒有錯誤。我已經發布的代碼和logcat請儘快幫我。Android Web服務連接錯誤
package com.androidlogin.androidmysql;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AndroidLoginActivity extends Activity {
private final String NAMESPACE = "//hello.android.com";
private final String URL = "http://192.168.1.210:8090/Myapp/services/Hello?wsdl";
private final String SOAP_ACTION = "//hello.android.com/sayHello";
private final String METHOD_NAME = "sayHello";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
loginAction();
//Toast.makeText(AndroidLoginActivity.this, "successfull", Toast.LENGTH_SHORT).show();
}
});
}
private void loginAction(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText userName = (EditText) findViewById(R.id.tf_userName);
String user_Name = userName.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.tf_password);
String user_Password = userPassword.getText().toString();
//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("userName");//Define the variable name in the web service method
unameProp.setValue(user_Name);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
//Pass value for Password variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
TextView result = (TextView) findViewById(R.id.tv_status);
result.setText(response.toString());
}
catch(Exception e){
}
}
}
**LOGCAT:**
10-22 15:14:21.614: D/dalvikvm(3946): GC_FOR_MALLOC freed 2697 objects/408656 bytes in 36ms
10-22 15:14:28.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 1314 objects/329208 bytes in 44ms
10-22 15:14:30.644: D/dalvikvm(3946): GC_FOR_MALLOC freed 662 objects/305112 bytes in 43ms
10-22 15:14:31.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 659 objects/305040 bytes in 43ms
10-22 15:14:37.695: D/dalvikvm(3946): GC_FOR_MALLOC freed 685 objects/305872 bytes in 31ms
10-22 15:14:38.805: D/dalvikvm(3946): GC_FOR_MALLOC freed 661 objects/305112 bytes in 43ms
10-22 15:14:39.035: D/dalvikvm(3946): GC_FOR_MALLOC freed 657 objects/305008 bytes in 30ms
10-22 15:14:39.245: D/dalvikvm(3946): GC_FOR_MALLOC freed 655 objects/304920 bytes in 29ms
10-22 15:14:41.484: W/KeyCharacterMap(3946): No keyboard for id 0
10-22 15:14:41.484: W/KeyCharacterMap(3946): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-22 15:14:43.064: D/dalvikvm(3946): GC_FOR_MALLOC freed 760 objects/308400 bytes in 41ms
10-22 15:14:44.334: D/dalvikvm(3946): GC_FOR_MALLOC freed 661 objects/305080 bytes in 34ms
10-22 15:14:46.424: D/dalvikvm(3946): GC_FOR_MALLOC freed 680 objects/305784 bytes in 35ms
10-22 15:14:47.624: D/dalvikvm(3946): GC_FOR_MALLOC freed 660 objects/305104 bytes in 40ms
10-22 15:14:47.854: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects/304960 bytes in 31ms
10-22 15:14:48.064: D/dalvikvm(3946): GC_FOR_MALLOC freed 655 objects/304928 bytes in 31ms
10-22 15:14:48.284: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects/304896 bytes in 30ms
10-22 15:14:48.504: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects/304936 bytes in 30ms
10-22 15:14:48.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects/305000 bytes in 30ms
10-22 15:15:59.594: W/KeyCharacterMap(3946): No keyboard for id 0
10-22 15:15:59.604: W/KeyCharacterMap(3946): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-22 15:15:59.725: W/IInputConnectionWrapper(3946): showStatusIcon on inactive InputConnection
10-22 15:16:15.134: D/dalvikvm(3946): GC_EXPLICIT freed 830 objects/309928 bytes in 117ms
10-22 15:17:41.604: D/dalvikvm(3946): GC_FOR_MALLOC freed 943 objects/316984 bytes in 31ms
10-22 15:21:55.215: W/KeyCharacterMap(3991): No keyboard for id 0
10-22 15:21:55.215: W/KeyCharacterMap(3991): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
請將您的所有網絡資料放在自己的主題中。例如。 AsyncTask查看一些內容:http://developer.android.com/training/basics/network-ops/connecting.html –
您是否包含Internet權限? – ZealDeveloper
@ZealDeveloper雅我做到了 –