Class not found exception

Hi All,

I am novice to j2me, I am tryiing communicate data between client and Java server. I have used code in forums,I have given project name client and midlet class name FileViewer.java.

It is compiling succesfully

but when I run it , it is giving

Unable to create Midlet FileViewer.java

java.lang.classnot found excetption: FileViewer.java

at com.sun.midp.midlet.selector.commandaction(+47)

at javax.microedition.lcdui.Display$displayaccessor.commandaction.(+152)

at com.sun.kvem.midp.lcdui.EmulEventHandler$eventloop.run(+459)

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import javax.microedition.io.*;

import java.io.*;

public class FileViewer extends MIDlet implements CommandListener

{

private Display display; // Reference to Display object

private TextBox tbViewer; // View file contents in a textbox

private Command cmView; // Command to view file

private Command cmExit; // Command to exit

private String url = "http://www.corej2me.com/midpbook_v1e1/scratch/fileViewer.hlp";

public FileViewer()

{

display = Display.getDisplay(this);

// Define commands

cmView = new Command("View", Command.SCREEN, 2);

cmExit = new Command("Exit", Command.EXIT, 1);

tbViewer = new TextBox("Viewer", "", 250, TextField.ANY);

tbViewer.addCommand(cmView);

tbViewer.addCommand(cmExit);

tbViewer.setCommandListener(this);

}

public void startApp()

{

display.setCurrent(tbViewer);

}

private void viewFile() throws IOException

{

HttpConnection http = null;

InputStream iStrm = null;

try

{

// Create the connection

http = (HttpConnection) Connector.open(url);

//-

// Client Request

//-

// 1) Send request method

http.setRequestMethod(HttpConnection.GET);

// 2) Send header information (this header is optional)

http.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");

// 3) Send body/data - No data for this request

//-

// Server Response

//-

// 1) Get status Line

System.out.println("Msg: " + http.getResponseMessage());

System.out.println("Code: " + http.getResponseCode());

// 2) Get header information

if (http.getResponseCode() == HttpConnection.HTTP_OK)

{

// 3) Get data (show the file contents)

iStrm = http.openInputStream();

int length = (int) http.getLength();

if (length > 0)

{

byte serverData[] = new byte[length];

iStrm.read(serverData);

tbViewer.setString(new String(serverData));

Alert alTest = new Alert("Alert Test", new String(serverData), null, null);

display.setCurrent(alTest);

}

}

}

finally

{

// Clean up

if (iStrm != null)

iStrm.close();

if (http != null)

http.close();

}

}

public void pauseApp()

{ }

public void destroyApp(boolean unconditional)

{ }

public void commandAction(Command c, Displayable s)

{

if (c == cmView)

{

try

{

viewFile();

}

catch (Exception e)

{

System.out.println(e.toString());

}

}

else if (c == cmExit)

{

destroyApp(false);

notifyDestroyed();

}

}

}

Can you please clarify. its urgent ,

Thanx.

[3539 byte] By [javadev2a] at [2007-11-27 9:20:34]
# 1
did you create the package before running it?
suparenoa at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
HiNope I have not created package before running. Can you plz suggest wht I have to do to take out this error. I am novice in this fieldThanks
javadev2a at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
> Nope I have not created package before running. Can> you plz suggest wht I have to do to take out this> errorlearning java and reading this article and searching on google... http://www.devarticles.com/c/a/Java/Getting-Started-with-J2ME/
suparenoa at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
Iam planning of buying that book. Still I dint get the answer can you plz suggest how I can take out this errorThanks,
javadev2a at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
i repeat my question:did you create the package before running it?if not, create the package and run it !!if you are working with an IDE (netbeans or eclipse), it will be easy, otherwise, install one ofthe IDE mentionned !!
suparenoa at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Hi saprano,

I have created package from project menu in ktool bar of j2me wireless toolkit and then build and then run but still it show this error class not found exception I am using wkt104... Is there any other methode to do package plz help me out..

Project "httpexample" loaded

Project settings saved

Building "httpexample"

Wrote c:\WTK104\apps\httpexample\bin\httpexample.jar

Wrote c:\WTK104\apps\httpexample\bin\httpexample.jad

Build complete

Project settings saved

Building "httpexample"

Build complete

Unable to create MIDlet HTTPMIDlet.java

java.lang.ClassNotFoundException: HTTPMIDlet.java

at com.sun.midp.midlet.Selector.commandAction(+47)

at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+152)

at com.sun.kvem.midp.lcdui.EmulEventHandler$EventLoop.run(+459)

Thanks

javadev2a at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
please download the wtk 2.2 or 2.5 and retry...
suparenoa at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
hi ..........u need to download higher version of wtk atleast 2.2 u r appln will run on itParagPatil
ParagPatila at 2007-7-12 22:13:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...