我已经将一个项目从 eclipse 导入到 android studio 中。该项目过去可以在 Eclipse 中正常工作。
我正在使用 SOAP 将我的 android 应用程序与我的服务器与 php 进行通信。我正在使用的库是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
当应用程序尝试从库中调用一个类时,应用程序崩溃了。
1)在这里我把我的连接方法并返回一个json数组。
import android.util.Log;
import motelalpaso.datos.Config;
import org.json.JSONArray;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class ConexionSoap {
public static JSONArray get_json_array(String method, String[]... params){
JSONArray array = new JSONArray();
SoapObject result = null;
SoapObject request = new SoapObject(Config.NAMESPACE, method);
for(int i = 0; i < params.length; i++){
request.addProperty(params[i][0], params[i][1]);
}
SoapSerializationEnvelope envelope = newSoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = false;
try{
envelope.setOutputSoapObject(request);
HttpTransportSE transporte = new HttpTransportSE(Config.URL);transporte.call(Config.NAMESPACE + "/" + method, envelope);Log.d("try", "Llego hasta aqui");
result = (SoapObject) envelope.bodyIn;
array = new JSONArray(result.getProperty(1).toString());
}catch(Exception e){
Log.d("Error", e.getMessage());
}
return array;
}
}
2) 这些是包含通信所需的参数。
public class Config {
public static final String NAMESPACE =
"http://www.motelalpaso.cl/webservice/android/";
public static final String BY_LOCATION = "obtener_por_location";
public static final String BY_NAME = "find_autos_by_namek";
public static final String URL =
"http://www.motelalpaso.cl/webservice/android/moteles.php";
}
3)最后我得到的错误..我希望你发现我做错了什么..
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
at motelalpaso.negocio.ConexionSoap.get_json_array(ConexionSoap.java:18)
at motelalpaso.ui.BuscarNombre$1$1.doInBackground(BuscarNombre.java:55)
at motelalpaso.ui.BuscarNombre$1$1.doInBackground(BuscarNombre.java:40)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)