0

I am creating a tcp server that communicates with C# and I accessed the coding from this website. I have downloaded the source code and added the external jars that were in the source code. Every time I try to run the server code on my app I get the NoClassDefFound in my LogCat. I was told this might have something to do with my buildpath which is why I mentioned the external jars. I have included my LogCat, Manifest, and Java. Thanks for the help.

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): at dalvik.system.NativeStart.main(Native Method)

The Java

    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;
}

MyResponse 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;
}
Sam Bevins
  • 1,939
  • 4
  • 21
  • 26

1 Answers1

2

I don't know the exact answer but i can give you a pointer:

The missing class is com.example.com.proto1.AndroidNetCommunicationClientActivity$1, since it ends with a '$1' it means it is the inner class of AndroidNetCommunicationClientActivity.

That Inner class should have a separate file called AndroidNetCommunicationClientActivity$1.class , so it seems that for some reason this file is not being generated.

You can try and extract the inner classes to an actual classes and see if that helps, or try to find out why the inner class file is not generated.

Hope that helps.

UPDATE

The comments are getting too long so i'll try and explain what i mean:

Inside of AndroidNetCommunicationClientActivityInner you have to inner classes declared: MyRequest,MyResponse.

You need to create 2 new java files: MyRequest.java and MyResponse.java and copy the code to them, so it'll look like:

MyRequest.java

 public class MyRequest {
        public String Text;
    }

MyResponse.java

public class MyResponse {
        public int Length;
    }

Then, DELETE those inner classes from AndroidNetCommunicationClientActivityInner and instead import the newly created classes, compile and redeploy the code.

Tomer
  • 17,787
  • 15
  • 78
  • 137
  • How do I extract the inner class? – Sam Bevins Aug 06 '12 at 15:34
  • Just create another java file and copy paste the code from the inner class. but remove the static declaration from the class. – Tomer Aug 06 '12 at 15:52
  • Ok, I did that. Now what do I do? – Sam Bevins Aug 06 '12 at 15:55
  • I'm assuming you removed the inner class definition and you are using the newly created class instead, just deploy the new code and try using it. – Tomer Aug 06 '12 at 16:16
  • have done that and I updated my question coding. I think I am just getting the same error but with my new class – Sam Bevins Aug 06 '12 at 16:36
  • Have you updated the code? it looks exactly the same to me. you still have inner classes declared – Tomer Aug 06 '12 at 16:38
  • Ok, it is completely updated now. I removed all of the static declarations but I still have the error – Sam Bevins Aug 06 '12 at 16:42
  • ok, I have applied your new directions and updated the coding in the question – Sam Bevins Aug 06 '12 at 17:04
  • No, you got it completely wrong! just create the classes as i posted, they don't need to inherit Activity and they don't need all that code, just as i posted. – Tomer Aug 06 '12 at 17:08
  • Ok, I updated. You'll have to forgive my slowness. I'm still pretty now to development – Sam Bevins Aug 06 '12 at 17:14
  • I tried to deploy it but it failed. When I said I updated it that included my logcat. I should have been clearer – Sam Bevins Aug 06 '12 at 17:26
  • You are still extending Activity in MyRequest and MyResponse, remove the `extends Activity` from thos classes, leave it only in your main class `AndroidNetCommunicationClientActivityInner` – Tomer Aug 06 '12 at 17:27