• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compile

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .....
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you have a classpath problem. Are the J2ME classes in your classpath?
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic