我正在使用 eclipse Juno
并且正在为 android 2.3.3 api level 10 开发
我正在尝试在 android 应用程序中创建 TelnetClient 以将命令发送到 telnet 服务器。出现错误后,我将代码简化为无济于事。
我的 Main.java
package com.vision.hometest;
import org.apache.commons.net.telnet.TelnetClient;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Main extends Activity implements OnClickListener{
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button) findViewById(R.id.b);
b.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
TelnetClient tc = new TelnetClient();
}
}
和 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" >
<Button
android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
我已添加权限
<uses-permission android:name="android.permission.INTERNET"/>
在清单中
我已经下载了 commons-net-3.1-bin.zip 二进制文件并将 commons-neet-3.1.jar 文件添加到 android 项目构建路径中。
但是,当我在扩展它时添加了罐子时,它说
Source attachment:(None)
Javadoc Location:(None)
Native libary location:(None)
Access rules :(No restrictions)
这些不应该说吗?
然后我编译项目并在模拟器上运行,当按下按钮时,应用程序强制关闭。
这是日志猫
07-10 11:18:18.137: E/dalvikvm(618): Could not find class'org.apache.commons.net.telnet.TelnetClient', referenced from method com.vision.hometest.Main.onClick
07-10 11:18:18.169: W/dalvikvm(618): VFY: unable to resolve new-instance 490 (Lorg/apache/commons/net/telnet/TelnetClient;) in Lcom/vision/hometest/Main;
07-10 11:18:18.169: D/dalvikvm(618): VFY: replacing opcode 0x22 at 0x0000
07-10 11:18:18.169: D/dalvikvm(618): VFY: dead code 0x0002-0005 in Lcom/vision/hometest/Main;.onClick (Landroid/view/View;)V
07-10 11:20:19.556: D/AndroidRuntime(618): Shutting down VM
07-10 11:20:19.556: W/dalvikvm(618): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-10 11:20:19.576: E/AndroidRuntime(618): FATAL EXCEPTION: main
07-10 11:20:19.576: E/AndroidRuntime(618): java.lang.NoClassDefFoundError: org.apache.commons.net.telnet.TelnetClient
07-10 11:20:19.576: E/AndroidRuntime(618): at com.vision.hometest.Main.onClick(Main.java:28)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.view.View.performClick(View.java:2485)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.view.View$PerformClick.run(View.java:9080)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.os.Handler.handleCallback(Handler.java:587)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.os.Looper.loop(Looper.java:123)
07-10 11:20:19.576: E/AndroidRuntime(618): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-10 11:20:19.576: E/AndroidRuntime(618): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 11:20:19.576: E/AndroidRuntime(618): at java.lang.reflect.Method.invoke(Method.java:507)
07-10 11:20:19.576: E/AndroidRuntime(618): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-10 11:20:19.576: E/AndroidRuntime(618): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-10 11:20:19.576: E/AndroidRuntime(618): at dalvik.system.NativeStart.main(Native Method)
07-10 11:20:22.036: I/Process(618): Sending signal. PID: 618 SIG: 9
最后
当我将程序创建为普通的 java 应用程序时,它可以完美运行。
我有没有做正确的事情,或者我错过了一些事情。如果有人可以帮助我,请提前感谢