2012-08-06 33 views
0

我正在创建一个与C#通信的tcp服务器,并且我访问了此编码website。我已经下载了源代码并添加了源代码中的外部罐子。每次尝试在我的应用程序上运行服务器代码时,我都会在LogCat中获得NoClassDefFound。我被告知这可能与我的构建路径有关,这就是为什么我提到了外部罐子。我已经包含了我的LogCat,Manifest和Java。谢谢您的帮助。设置tcp服务器时出现NoClassDefFound错误

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(本机方法)

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爪哇

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

看到[this](http://stackoverflow.com/a/10046725/1289716)这个答案可能对你有帮助 – MAC 2012-08-06 13:41:22

+0

是类的eneter.net.system.EventHandler存在吗?我认为有一些问题引用EventHandler – nandeesh 2012-08-06 14:03:31

+0

你究竟是什么意思?我是相当新的,所以你必须具体与我 – 2012-08-06 14:30:25

回答

2

我不知道确切的答案,但我可以给你一个指针:

的缺失类是com.example.com.proto1.AndroidNetCommunicationClientActivity$1,因为它有一个“$ 1”结尾意思是它的内部类的AndroidNetCommunicationClientActivity

内部类应该有一个单独的文件,名为AndroidNetCommunicationClientActivity$1.class,所以似乎由于某种原因,这个文件没有被生成。

您可以尝试将内部类提取到实际的类,并查看是否有帮助,或尝试找出内部类文件未生成的原因。

希望有所帮助。

UPDATE

的意见越来越太长,所以我会尽量解释一下我的意思是:

里面的AndroidNetCommunicationClientActivityInner你必须声明内部类:MyRequest,MyResponse。

您需要创建2个新的Java文件:MyRequest.java和MyResponse.java和代码复制到他们,所以它会看起来像:

MyRequest.java

public class MyRequest { 
     public String Text; 
    } 

MyResponse.java

public class MyResponse { 
     public int Length; 
    } 

然后,DELETE来自AndroidNetCommunicationClientActivityInner的那些内部类,而是导入新创建的类,编译并重新部署代码。

+0

我如何提取内部类? – 2012-08-06 15:34:51

+0

只需创建另一个java文件并复制粘贴内部类的代码即可。但是从类中移除静态声明。 – Tomer 2012-08-06 15:52:06

+0

好吧,我做到了。现在我该怎么办? – 2012-08-06 15:55:56

相关问题