2013-04-26 63 views
0

我試圖做一個簡單的應用程序來拿起一個web服務的字符串,我已經下載了包ksopa2,數量和做的正確的數據(在互聯網教程上測試),我得到下面的錯誤你可以,你知道那可能是?非常感謝你!錯誤ksoap2序列化

應用:

public class MainActivity extends Activity { 

private static final String SOAP_ACTION = "http://tempuri.org/devuelveString"; //Variables 
private static final String METHOD_NAME = "devuelveString"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL = "http://localhost:52335/Service1.asmx"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Button boton = (Button) findViewById(R.id.Bboton); 

    boton.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      InvocarWs(); //call the method 

     } 
    }); 
} 

public void InvocarWs() { 
    System.out.println("llama al metodo"); 
    try { 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
       SoapEnvelope.VER11); // utilizar la version que 
             // corresponda:11 o 12 
     envelope.dotNet = true; // para WS ASMX, sólo si fue construido con 
           // .Net 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE transporte = new HttpTransportSE(URL); 

     transporte.call(SOAP_ACTION, envelope); 

     SoapPrimitive resultado = (SoapPrimitive) envelope.getResponse(); 

     System.out.println("" + resultado.toString()); 

    } catch (Exception e) { 
     System.out.println("catch"); 
    } 
} 

}

錯誤logvcat

04-26 08:03:08.731: E/AndroidRuntime(536): FATAL EXCEPTION: main 
04-26 08:03:08.731: E/AndroidRuntime(536): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject 
04-26 08:03:08.731: E/AndroidRuntime(536): at com.example.prueba.Conexion.InvocarWs(Conexion.java:24) 
04-26 08:03:08.731: E/AndroidRuntime(536): at com.example.prueba.MainActivity$1.onClick(MainActivity.java:25) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.view.View.performClick(View.java:2485) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.view.View$PerformClick.run(View.java:9080) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.os.Handler.handleCallback(Handler.java:587) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.os.Looper.loop(Looper.java:123) 
04-26 08:03:08.731: E/AndroidRuntime(536): at android.app.ActivityThread.main(ActivityThread.java:3683) 
04-26 08:03:08.731: E/AndroidRuntime(536): at java.lang.reflect.Method.invokeNative(Native Method) 
04-26 08:03:08.731: E/AndroidRuntime(536): at java.lang.reflect.Method.invoke(Method.java:507) 
04-26 08:03:08.731: E/AndroidRuntime(536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
04-26 08:03:08.731: E/AndroidRuntime(536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
04-26 08:03:08.731: E/AndroidRuntime(536): at dalvik.system.NativeStart.main(Native Method) 

回答

1

您需要的jar(S)複製到該目錄libs項目中。 ADK從該文件夾中選擇庫並將它們轉換爲針對Dalvik優化的類。

Creating a folder "libs" in the project 
Copying the external jars in to the folder 
Refresh the folder 
Go to properties -> Build path -> Add Jar (not external JAR) 
Clean the project 
Restart Eclipse 

試試這個也

Go to the Order and Export tab on the same popup window 
Check the box against the newly added jar 
+0

我有,但仍然沒有工作 – CristianCV 2013-04-26 08:29:10

+0

你從libs目錄 – 2013-04-26 08:30:14

+0

添加在構建路徑的jar文件是的,我已經做 – CristianCV 2013-04-26 08:34:25

0

ksoap2罈子只需複製到您的libs文件夾。然後從你構建的路徑添加jar文件到你的項目中。

刷新您的項目並運行。它會運行良好。

+0

我這樣做,但仍不工作 – CristianCV 2013-04-26 08:30:19

0

試試這個:

步驟:

步驟01:轉至項目 - >項目屬性 - > Java構建路徑 - >庫 - >添加外部JAR

步驟-02:從目的地選擇JAR文件

步驟03:在同一個窗口中選擇庫的下一個選項卡是訂單和出口

步驟-04:訂單和導出 - >選中你的庫的複選框 - >確定

不要創建任何libs文件夾,它會自動執行。

我希望這一個可以幫助你... :)