1

我已经将一个项目从 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)
4

3 回答 3

7

首先将您的库放入 libs 文件夹,然后右键单击它并选择“添加为库”。打开 build.gradle 文件并添加你的库

dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar')
}

最后转到终端中的根文件夹并运行“./gralew clean”,重建并运行您的 android 应用程序。

于 2013-05-27T00:12:47.440 回答
0

您需要在通话中添加“”:

transporte.call("\"" + Config.NAMESPACE + "/" + method + "\"",  envelope); //It should work fine
于 2013-05-26T02:59:53.647 回答
0

在您的应用程序 gradle 文件中添加存储库...

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}

然后添加编译依赖

dependencies {
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
}
于 2017-02-20T07:40:42.530 回答