1

我尝试使用http://codeoncloud.blogspot.it/2012/03/android-mysql-client.html中的代码来制作我自己的应用程序,但它不起作用。

1)我使用 MySQL Workbench 创建了一个数据库。

2)在 Eclipse (Juno) 中,我使用 AXISv2 创建了 Web 服务

3)使用 ADK,我创建了应用程序。

首先我运行 MySQL 服务器,然后在 APACHE Tomcat 中运行 web 服务。这个过程并不是真正的问题。我检查了一切都在运行。但是,当我运行该应用程序时,Android 刚刚停止工作。

这是日志猫。

07-19 18:28:59.253: E/Trace(808): error opening trace file: No such file or directory (2)
07-19 18:28:59.473: E/dalvikvm(808): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.example.koios_beta4.MainActivity.onCreate
07-19 18:28:59.543: W/dalvikvm(808): VFY: unable to resolve new-instance 630 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/example/koios_beta4/MainActivity;
07-19 18:28:59.543: D/dalvikvm(808): VFY: replacing opcode 0x22 at 0x0003
07-19 18:28:59.573: D/dalvikvm(808): DexOpt: unable to opt direct call 0x10b2 at 0x09 in Lcom/example/koios_beta4/MainActivity;.onCreate
07-19 18:28:59.573: D/dalvikvm(808): DexOpt: unable to opt direct call 0x10b4 at 0x10 in Lcom/example/koios_beta4/MainActivity;.onCreate
07-19 18:28:59.573: D/dalvikvm(808): DexOpt: unable to opt direct call 0x10b7 at 0x1a in Lcom/example/koios_beta4/MainActivity;.onCreate
07-19 18:28:59.623: D/AndroidRuntime(808): Shutting down VM
07-19 18:28:59.694: W/dalvikvm(808): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-19 18:28:59.713: E/AndroidRuntime(808): FATAL EXCEPTION: main
07-19 18:28:59.713: E/AndroidRuntime(808): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
07-19 18:28:59.713: E/AndroidRuntime(808):  at com.example.koios_beta4.MainActivity.onCreate(MainActivity.java:23)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.Activity.performCreate(Activity.java:5104)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.os.Looper.loop(Looper.java:137)
07-19 18:28:59.713: E/AndroidRuntime(808):  at android.app.ActivityThread.main(ActivityThread.java:5041)
07-19 18:28:59.713: E/AndroidRuntime(808):  at java.lang.reflect.Method.invokeNative(Native Method)
07-19 18:28:59.713: E/AndroidRuntime(808):  at java.lang.reflect.Method.invoke(Method.java:511)
07-19 18:28:59.713: E/AndroidRuntime(808):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-19 18:28:59.713: E/AndroidRuntime(808):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-19 18:28:59.713: E/AndroidRuntime(808):  at dalvik.system.NativeStart.main(Native Method)

这是 MainActivity.java 中的代码

package com.example.koios_beta4;

import android.os.Bundle;
import android.app.Activity;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.TextView;

public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.androidapp.com/loginData";
private static final String METHOD_NAME = "loginData";
private static final String NAMESPACE = "http://ws.androidapp.com";
private static final String URL = "http://localhost:8080/Koios_webapp/services/Login_instance?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject(request);

    HttpTransportSE ht = new HttpTransportSE(URL);
    try {
        ht.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        SoapPrimitive s = response;
        String str = s.toString();
        String resultArr[] = str.split("&");//Result string will split & store in an array

        TextView tv = new TextView(this);

        for(int i = 0; i<resultArr.length;i++){
        tv.append(resultArr[i]+"\n\n");
       }
        setContentView(tv);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

这是activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="94dp"
    android:text="@string/test" />

4

0 回答 0