简体   繁体   English

为什么在我的android应用程序中创建TelnetClient时出现错误?

[英]Why am i getting an error when when creating a TelnetClient in my android application?

i am using the eclipse Juno 我正在使用月食朱诺
and am developing for android 2.3.3 api level 10 并正在为android 2.3.3 api级别10开发

i am trying to create a TelnetClient in an android application to send commands to a telnet server. 我正在尝试在android应用程序中创建TelnetClient,以将命令发送到telnet服务器。 Having had the error i have simplified the code to this without avail. 遇到错误后,我将代码简化为无济于事。

My Main.java 我的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();

}


}

and the main.xml 和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>

I have added the permission 我已添加权限

<uses-permission android:name="android.permission.INTERNET"/>

in the manifest 在清单中

I have down loaded the commons-net-3.1-bin.zip binary file and added the commons-neet-3.1.jar file to the android projects build path. 我已经下载了commons-net-3.1-bin.zip二进制文件,并将commons-neet-3.1.jar文件添加到android项目的构建路径中。

However when i have added the jar when i expand it it says 但是,当我在扩展罐子时添加了罐子时,它说

Source attachment:(None)
Javadoc Location:(None)
Native libary location:(None)
Access rules :(No restrictions)

should these say none? 这些应该不说吗?

i then compile the project and run on an emulator and when the button is pressed the application force closes. 然后我编译项目并在仿真器上运行,当按下按钮时,应用程序强制关闭。

this is the logcat 这是logcat

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
  • Finally 最后

    When i create the programe as a normal java aplication it works perfectly. 当我将程序创建为普通的Java应用程序时,它可以完美运行。

Have i not done something correctly or have i missed some thing out. 我没有正确地做某件事还是错过了一些事情。 thanks in advance if any one can help me out 预先感谢任何人能帮助我

You did not include the Apache Commons Net library in your build path. 您没有在构建路径中包括Apache Commons Net库。 You need to include the Library by downloading it from http://commons.apache.org/net/download_net.cgi and then in Eclipse right click on your project, Build Path -> Configure Build Path, then click on the "Libraries" tab then click "Add External JAR" and then navigate to the jar file for the commons-net that you downloaded. 您需要通过从http://commons.apache.org/net/download_net.cgi下载它来包含库,然后在Eclipse中右键单击您的项目,构建路径->配置构建路径,然后单击“库”标签,然后单击“添加外部JAR”,然后导航到您下载的commons-net的jar文件。

I created nearly the same code a few weeks ago and have the same problem. 几周前我创建了几乎相同的代码,并且遇到了相同的问题。 Android simply crashes when creating the "TelnetClient tc = new TelnetClient();" 创建“ TelnetClient tc = new TelnetClient();”时,Android只会崩溃。 object. 宾语。 I too found that it works perfectly in Java but on Android it instantly crashes. 我也发现它可以在Java中完美运行,但在Android上会立即崩溃。

Obviously some kind of problem with Apache Commons telnet. 显然,Apache Commons telnet存在某种问题。 I have never seen anyone successfully use Apache Commons telnet library to connect to telnet from android. 我从未见过有人成功使用Apache Commons telnet库从android连接到telnet。 It simply does not work. 它根本行不通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在运行Android应用程序时在DDMS中出现这些错误? - Why am I getting these errors in DDMS when running android application? 我的 Android 应用程序出现错误 - I am getting an error in my android application 为什么在运行应用程序时出现此错误? - Why am I getting this error when I run my app? 为什么在android中使用webview时出现错误? - Why I am getting an error when I use webview in android? 为什么在尝试与我的服务器通信时出现此错误? - Why am i getting this error when trying to communicate with my server? 为什么在我的项目中实现 mapbox 时会出错? - Why am I getting error when implementing mapbox to my project? 为什么在创建新的 android 项目时会出现渲染错误? - Why am I getting rendering errors when creating a new android project? 为什么我的Android应用程序上出现空字符串? - Why am I getting empty string on my android application? 为什么我在 Cloud Firestore (24.1.2) 中出现内部错误。 仅在运行浓缩咖啡测试时在我的 Android 应用中? - Why am I getting Internal error in Cloud Firestore (24.1.2). In my Android app only when running an espresso test? 运行 Android 应用程序时出现错误:app: dataBindingMergeDependencyArtifactsDebug - I am getting error when I run the Android application: app: dataBindingMergeDependencyArtifactsDebug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM