0

我正在开发一个 Android 应用程序,在我的项目中使用Java并尝试使用我的用户定义类。MarportWS我已经把它们放到了 src 文件夹中,并且编译得很完美。但是在运行时,我收到异常,指出该类未定义。如果您有任何想法,请提供帮助。

顺便说一句,问题出在gateOut功能上,而不是 gateIn

这是我的代码:

package com.example.marport;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class Giriscikis extends Activity {

    final static String NAMESPACE = "http://webservice.marport.dcat.com/";
    final static String METHOD_NAME2 = "gateIn";
    final static String SOAP_ACTION2 = "http://webservice.marport.dcat.com/gateIn";
    final static String URL = "http://192.168.1.164:8070/mws/services/MarportWebServicePort?wsdl";

    public String denemecikis;
    private EditText cikis;
    private EditText giris;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.giriscikis);

        cikis = (EditText) findViewById(R.id.etCikis);
        giris = (EditText) findViewById(R.id.etGiris);

        SoapObject Request2 = new SoapObject(NAMESPACE, METHOD_NAME2);

        SoapSerializationEnvelope soapEnvelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapEnvelope2.dotNet = false;


        soapEnvelope2.setOutputSoapObject(Request2);

        HttpTransportSE aht = new HttpTransportSE(URL);

        //////////////////////////////////////////////////////// 
        MarportWS temp = new MarportWS();
        try {
            denemecikis = String.valueOf(temp.gateOut().intValue()) ;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        cikis.setText(denemecikis);
        /////////////////////////////////////////////////////// 

        try {
            aht.call(SOAP_ACTION2, soapEnvelope2);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            SoapPrimitive result2 = (SoapPrimitive) soapEnvelope2.getResponse();
            giris.setText(result2.toString());
        } catch (SoapFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

和日志:

09-03 13:56:32.594: E/AndroidRuntime(751): FATAL EXCEPTION: main
09-03 13:56:32.594: E/AndroidRuntime(751): java.lang.NoClassDefFoundError: com.example.marport.MarportWS
09-03 13:56:32.594: E/AndroidRuntime(751):  at com.example.marport.Giriscikis.onCreate(Giriscikis.java:49)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.os.Looper.loop(Looper.java:123)
09-03 13:56:32.594: E/AndroidRuntime(751):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 13:56:32.594: E/AndroidRuntime(751):  at java.lang.reflect.Method.invokeNative(Native Method)
09-03 13:56:32.594: E/AndroidRuntime(751):  at java.lang.reflect.Method.invoke(Method.java:521)
09-03 13:56:32.594: E/AndroidRuntime(751):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 13:56:32.594: E/AndroidRuntime(751):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 13:56:32.594: E/AndroidRuntime(751):  at dalvik.system.NativeStart.main(Native Method)

谢谢。

4

1 回答 1

0

我已经回答了一个与您有关的问题。看看这里

是的,这是因为您的 .jar 文件没有正确导入。请按照以下步骤操作 -

  1. 将 .jar 文件放在项目的 libs 文件夹中。

  2. 将其导入您的项目。并且,GoTo 项目 -> 属性 -> Java 构建路径 -> 订单选项卡。

  3. 检查您的 .jar 文件是否已检查并按第一顺序放置。这是主要的事情。

希望这些步骤对您有所帮助。看看下面的图片 -

图片

于 2012-09-03T14:08:00.807 回答