Reputation: 81
i am using the eclipse Juno
and am developing for android 2.3.3 api level 10
i am trying to create a TelnetClient in an android application to send commands to a telnet server. Having had the error i have simplified the code to this without avail.
My 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
<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.
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
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.
Have i not done something correctly or have i missed some thing out. thanks in advance if any one can help me out
Upvotes: 1
Views: 1772
Reputation: 23
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();" object. I too found that it works perfectly in Java but on Android it instantly crashes.
Obviously some kind of problem with Apache Commons telnet. I have never seen anyone successfully use Apache Commons telnet library to connect to telnet from android. It simply does not work.
Upvotes: 1
Reputation: 1054
You did not include the Apache Commons Net library in your build path. 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.
Upvotes: 1