• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

problem with CommandListener -- IS IT A BUG

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
can u pls see the following code n tell me if therz any wrong usage of CommandListener .
As the System out i have given inside the CommandAction is not getting printed on the console untill i close the emulator completely .
My IDE : FORTE FOR JAVA RELEASE 2.0 COMMUNITY EDITION integrated with j2me1.0.2 .
If i click on the "exit" button n times it stays the same ( doesnt respond ) untill i close the emulator and then i prints the System out n times..
Is there any specific problem or specific way in which i have to use the CommandListener .
This looks pretty ordinary but is creating a lot of problem for me in my development of an embedded application.
Can u pls let me know abt the solution for this as soon as possible..
NOTE : I have commented some of the lines and also methods to make it the simplest MIDLET to check for CommandAction just to make sure that itz not going wrong elsewhere..
Thanq in advance
CODE BELOW---
package TestCommands;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
/**
* An example MIDlet with simple "Hello" text and an Exit command.
* Refer to the startApp, pauseApp, and destroyApp
* methods so see how each handles the requested transition.
*
* @author sjatla
* @version
*/
public class TestCommands extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Display display; // The display for this MIDlet
public TestCommands() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.SCREEN, 2);
}
/**
* Start up the Hello MIDlet by creating the TextBox and associating
* the exit command and listener.
*/
public void startApp() {
TextBox t = new TextBox("Hello MIDlet", "Test string", 256, 0);
t.addCommand(exitCommand);
t.setCommandListener(this);
display.setCurrent(t);
}
/**
* Pause is a no-op since there are no background activities or
* record stores that need to be closed.
*/
public void pauseApp() {
}
/**
* Destroy must cleanup everything not handled by the garbage collector.
* In this case there is nothing to cleanup.
*/
public void destroyApp(boolean unconditional) {
}

private void downloadPage(String url) throws IOException {
/* StringBuffer b = new StringBuffer();
InputStream is = null;
HttpConnection c = null;
TextBox t = null;
System.out.println("the url is " + url);
try {
long len = 0 ;
int ch = 0;

c = (HttpConnection)Connector.open(url);
System.out.println("the connec is " + c);
is = c.openInputStream();
System.out.println("before c.getLength() & is is " + is);
len =c.getLength() ;
System.out.println("the length is " + len);
if ( len != -1) {
// Read exactly Content-Length bytes
for (int i =0 ; i < len ; i++ )
if ((ch = is.read()) != -1)
b.append((char) ch);
} else {
// Read till the connection is closed.
while ((ch = is.read()) != -1) {
len = is.available() ;
b.append((char)ch);
}
}
t = new TextBox("hello again....", b.toString(), 1024, 0);
} catch (Exception e)
{
System.out.println("Exception in downloadPage is "+ e);
}
finally {
is.close();
c.close();
}
display.setCurrent(t);
**/
}
/*
* Respond to commands, including exit
* On the exit command, cleanup and notify that the MIDlet has been destroyed.
*/
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
System.out.println("am in exitCommand");
/*
try{
downloadPage("http://localhost:7001/order1";);
}catch(Exception e){e.printStackTrace();}
*/
}
}
}
thanx & regards
sans
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic