0

C# と通信する tcp サーバーを作成しており、このWeb サイトからコーディングにアクセスしました。ソース コードをダウンロードし、ソース コードに含まれていた外部 jar を追加しました。アプリでサーバー コードを実行しようとするたびNoClassDefFoundに、LogCat に . これはビルドパスと関係があるかもしれないと言われたので、外部 jar について言及しました。LogCat、マニフェスト、および Java を含めました。助けてくれてありがとう。

08-06 13:31:54.989: W/dalvikvm(5164): threadid=1: thread exiting with uncaught exception (group=0x401f3760)
08-06 13:31:54.989: E/AndroidRuntime(5164): FATAL EXCEPTION: main
08-06 13:31:54.989: E/AndroidRuntime(5164): java.lang.NoClassDefFoundError: com.example.com.proto1.AndroidNetCommunicationClientActivityInner$1
08-06 13:31:54.989: E/AndroidRuntime(5164):     at com.example.com.proto1.AndroidNetCommunicationClientActivityInner.<init>(AndroidNetCommunicationClientActivityInner.java:102)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at java.lang.Class.newInstanceImpl(Native Method)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at java.lang.Class.newInstance(Class.java:1301)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1733)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1834)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.ActivityThread.access$500(ActivityThread.java:122)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1027)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.os.Looper.loop(Looper.java:132)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at android.app.ActivityThread.main(ActivityThread.java:4126)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at java.lang.reflect.Method.invokeNative(Native Method)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at java.lang.reflect.Method.invoke(Method.java:491)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-06 13:31:54.989: E/AndroidRuntime(5164):     at dalvik.system.NativeStart.main(Native Method)

:31:54.989: E/AndroidRuntime(5164): dalvik.system.NativeStart.main(ネイティブメソッド)

ジャバ

    package com.example.com.proto1;

import eneter.messaging.diagnostic.EneterTrace;
import eneter.messaging.endpoints.typedmessages.*;
import eneter.messaging.messagingsystems.messagingsystembase.*;
import eneter.messaging.messagingsystems.tcpmessagingsystem.TcpMessagingSystemFactory;
import eneter.net.system.EventHandler;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class AndroidNetCommunicationClientActivityInner extends Activity {

    // UI controls
    private Handler myRefresh = new Handler();
    private EditText myMessageTextEditText;
    private EditText myResponseEditText;
    private Button mySendRequestBtn;

    // Sender sending MyRequest and as a response receiving MyResponse.
    private IDuplexTypedMessageSender<MyResponse, MyRequest> mySender;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tcp_server);

        // Get UI widgets.
        myMessageTextEditText = (EditText) findViewById(R.id.messageTextEditText);
        myResponseEditText = (EditText) findViewById(R.id.messageLengthEditText);
        mySendRequestBtn = (Button) findViewById(R.id.sendRequestBtn);

        // Subscribe to handle the button click.
        mySendRequestBtn.setOnClickListener(myOnSendRequestClickHandler);

        try {
            openConnection();
        } catch (Exception err) {
            EneterTrace.error("Open connection failed.", err);
        }
    }

    @Override
    public void onDestroy() {
        // Stop listening to response messages.
        mySender.detachDuplexOutputChannel();
    }

    private void openConnection() throws Exception {
        // Create sender sending MyRequest and as a response receiving
        // MyResponse
        IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory();
        mySender = aSenderFactory.createDuplexTypedMessageSender(
                MyResponse.class, MyRequest.class);

        // Subscribe to receive response messages.
        mySender.responseReceived().subscribe(myOnResponseHandler);

        // Create TCP messaging for the communication.
        // Note: 10.0.2.2 is a special alias to the loopback (127.0.0.1)
        // on the development machine
        IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
        IDuplexOutputChannel anOutputChannel = aMessaging
                .createDuplexOutputChannel("tcp://70.63.35.218/");

        // Attach the output channel to the sender and be able to send
        // messages and receive responses.
        mySender.attachDuplexOutputChannel(anOutputChannel);
    }

    private void onSendRequest(View v) {
        // Create the request message.
        MyRequest aRequestMsg = new MyRequest();
        aRequestMsg.Text = myMessageTextEditText.getText().toString();

        // Send the request message.
        try {
            mySender.sendRequestMessage(aRequestMsg);
        } catch (Exception err) {
            EneterTrace.error("Sending the message failed.", err);
        }
    }

    private void onResponseReceived(Object sender,
            final TypedResponseReceivedEventArgs<MyResponse> e) {
        // Display the result - returned number of characters.
        // Note: Marshal displaying to the correct UI thread.
        myRefresh.post(new Runnable() {
            public void run() {
                myResponseEditText.setText(Integer.toString(e
                        .getResponseMessage().Length));
            }
        });
    }

    private EventHandler<TypedResponseReceivedEventArgs<MyResponse>> myOnResponseHandler

    = new EventHandler<TypedResponseReceivedEventArgs<MyResponse>>() {
        public void onEvent(Object sender,
                TypedResponseReceivedEventArgs<MyResponse> e) {
            onResponseReceived(sender, e);
        }
    };

    private OnClickListener myOnSendRequestClickHandler = new OnClickListener() {
        public void onClick(View v) {
            onSendRequest(v);
        }
    };
}

MyRequest Java

  package com.example.com.proto1;


public class MyRequest {
    // Request message type
    // The message must have the same name as declared in the service.
    // Also, if the message is the inner class, then it must be static.
    public String Text;
}

マイレスポンス Java

  package com.example.com.proto1;


public class MyResponse {
    // Request message type
    // The message must have the same name as declared in the service.
    // Also, if the message is the inner class, then it must be static.
    public int Length;
}
4

1 に答える 1

2

私は正確な答えを知りませんが、私はあなたにポインターを与えることができます:

欠落しているクラスはcom.example.com.proto1.AndroidNetCommunicationClientActivity$1、'$ 1'で終わるため、それがの内部クラスであることを意味しAndroidNetCommunicationClientActivityます。

その内部クラスには、という別のファイルが必要AndroidNetCommunicationClientActivity$1.classであるため、何らかの理由でこのファイルが生成されていないようです。

内部クラスを実際のクラスに抽出して、それが役立つかどうかを確認したり、内部クラスファイルが生成されない理由を調べたりすることができます。

お役に立てば幸いです。

アップデート

コメントが長くなりすぎているので、私が何を意味するのかを説明しようと思います。

あなたの内部ではAndroidNetCommunicationClientActivityInner、宣言された内部クラスを持っている必要があります:MyRequest、MyResponse。

MyRequest.javaとMyResponse.javaの2つの新しいJavaファイルを作成し、それらにコードをコピーする必要があるため、次のようになります。

MyRequest.java

 public class MyRequest {
        public String Text;
    }

MyResponse.java

public class MyResponse {
        public int Length;
    }

次に、それらの内部クラスをから削除AndroidNetCommunicationClientActivityInnerし、代わりに新しく作成されたクラスをインポートし、コードをコンパイルして再デプロイします。

于 2012-08-06T13:47:14.230 に答える