aspose file tools*
The moose likes Java Micro Edition and the fly likes Compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Compile" Watch "Compile" New topic
Author

Compile

Graham Thorpe
Ranch Hand

Joined: Mar 25, 2002
Posts: 265
Can any body tell me how to compile small j2me pgm.
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* An example MIDlet to invoke a CGI script.
*/
public class FirstMidletServlet extends MIDlet {
private Display display;

String url = "http://developer.java.sun.com/servlet/HelloServlet";

public FirstMidletServlet() {
display = Display.getDisplay(this);
}
/**
* Initialization. Invoked when we activate the MIDlet.
*/
public void startApp() {
try {
invokeServlet(url);
} catch (IOException e) {
System.out.println("IOException " + e);
e.printStackTrace();
}
}
/**
* Pause, discontinue ....
*/
public void pauseApp() {

}
/**
* Destroy must cleanup everything.
*/
public void destroyApp(boolean unconditional) {
}
/**
* Prepare connection and streams then invoke servlet.
*/
void invokeServlet(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
StringBuffer b = new StringBuffer();
TextBox t = null;
try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");
is = c.openDataInputStream();
int ch;
while ((ch = is.read()) != -1) {
b.append((char) ch);
//System.out.println((char)ch);
}
t = new TextBox("First Servlet", b.toString(), 1024, 0);
} finally {
if(is!= null) {
is.close();
}
if(c != null) {
c.close();
}
}
display.setCurrent(t);
}
}

When i complie this pgm i got following errors.
C:\j2me>javac FirstMidletservlet.java
FirstMidletservlet.java:2: package javax.microedition.io does not exist
import javax.microedition.io.*;
^
FirstMidletservlet.java:3: package javax.microedition.lcdui does not ex
import javax.microedition.lcdui.*;
^
FirstMidletservlet.java:4: package javax.microedition.midlet does not e
import javax.microedition.midlet.*;
^
FirstMidletservlet.java:10: cannot resolve symbol
symbol : class MIDlet
location: class FirstMidletServlet
public class FirstMidletServlet extends MIDlet {
^
FirstMidletservlet.java:12: cannot resolve symbol
symbol : class Display
location: class FirstMidletServlet
private Display display;
^
FirstMidletservlet.java:18: cannot resolve symbol
symbol : variable Display
location: class FirstMidletServlet
display = Display.getDisplay(this);
^
FirstMidletservlet.java:51: cannot resolve symbol
symbol : class HttpConnection
location: class FirstMidletServlet
HttpConnection c = null;
^
FirstMidletservlet.java:54: cannot resolve symbol
symbol : class TextBox
location: class FirstMidletServlet
TextBox t = null;
^
FirstMidletservlet.java:56: cannot resolve symbol
symbol : class HttpConnection
location: class FirstMidletServlet
c = (HttpConnection)Connector.open(url);
^
FirstMidletservlet.java:56: cannot resolve symbol
symbol : variable Connector
location: class FirstMidletServlet
c = (HttpConnection)Connector.open(url);
^
FirstMidletservlet.java:57: cannot resolve symbol
symbol : variable HttpConnection
location: class FirstMidletServlet
c.setRequestMethod(HttpConnection.GET);
^
FirstMidletservlet.java:67: cannot resolve symbol
symbol : class TextBox
location: class FirstMidletServlet
t = new TextBox("First Servlet", b.toString(), 1024, 0);
^
12 errors

any body help me ...pls .....
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
It looks like you have a classpath problem. Are the J2ME classes in your classpath?


Matthew Phillips
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
glkrr reddy,
Your problem is class path now for resolving this problem there are two ways
1- use some IDE which supports j2me like j2mewtk K-Toolbar or jbuilder mobileset 2.0
2- use following steps for compiling and packaging the application
a) Compilation
javac -g -bootclasspath 'path of the api jar files' -d 'destination dir for class file' filename.java
b) Preverifying
preverify -classpath d:\smtkm50 'path of the api jar files;path of the compiled class file' -d 'destination path for the preverified class' classname
c) jar cf 'jar filename' "classes to be added in this jar file separated by coma'
3- Running the application
Now make a .jad file and install the whole package( ie .jad file + jar file) into the phone
Hope it will help you
Rishi
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Sorry there is some modification in above posting part 2-b) It is as follows
2-b) Preverifying
preverify -classpath 'path of the api jar files;path of the compiled class file' -d 'destination path for the preverified class' classname
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compile