J2ME, Canvas,

B

Boki

Hi, All,
I start up from a MIDlet and transfer to a GUI Canvas when
press a soft key, but the GUI.java
never answer my addCommand request ....

I mean, these soft buttons I add, they didn't show up on the screen, and I
my call code is :

====================
display.setCurrent(gui)
=======================

what's wrong...@@?

Best regards,
Boki.
 
D

Darryl Pierce

Boki said:
I start up from a MIDlet and transfer to a GUI Canvas when
press a soft key, but the GUI.java
never answer my addCommand request ....

Please rephrase your message. It is very unclear. I understand that
you're displaying a class that extends Canvas, but what do you mean by
"never answer my addCommand request"? Do you mean you're creating an
instance of Command and calling Canvas.addCommand()?

If so, please post the code for where you create the Command, where you
create the Canvas and where you add the Command to the Canvas. Canvas
objects can and do display Commands, so the problem's in your code
somewhere...
 
B

Boki

Hi Darry,
Thank you very much for your reply.
I solve this problem this morning already, I set a wrong

display.setCurrent ( XXX )

but, just now, I have another problem,

I create a Form from MIDlet and show it when MIDlet startApp(),

I will change the screen to GUI.java when I press a soft button,

right now, I can't back to the Form of MIDlet...

GUI.java ( extends Canvas ) can't destroy()..

I need help.

Best regards,
Boki.
 
T

Tor Iver Wilhelmsen

Boki said:
right now, I can't back to the Form of MIDlet...

GUI.java ( extends Canvas ) can't destroy()..

Why not add a Comand to GUI.java that will let you switch back to the
form?
 
B

Boki

sure, do you mean

when I press a soft button
and that perform:

display.setCurrent( Main form ) ?

Best regards,
Boki.
 
D

Darryl Pierce

Boki said:
but, just now, I have another problem,

I create a Form from MIDlet and show it when MIDlet startApp(),

I will change the screen to GUI.java when I press a soft button,

right now, I can't back to the Form of MIDlet...

GUI.java ( extends Canvas ) can't destroy()..

I'm sorry, the language barrier is really hard to get past. If you have
a Displayable object, such as a Form, then calling
Display.getDisplay([your active MIDlet]).setCurrent([the Displayable])
will change the active display to the one you passed in. Can you post
the code where you're changing the display please?
 
B

Boki

I got it.
By the way, could we destroy it to release memory?

Thank you very much.

Best regards,
Boki.
 
D

Darryl Pierce

Boki said:
I got it.
By the way, could we destroy it to release memory?

No. Garbage collection is out of your hands with all forms of Java. You
can only dispose of all references to the Object; the VM will reclaim
memory when it needs it.
 
B

Boki

It seems not work on my code...
Even I declare <Main form of activate MIDlet> as public, the GUI.java can't
recognize that symbol.

gui.java
....
....
public void commandAction(Command c, Displayable s) {
....
display.setCurrent(A.B);
^^^^^^^^^^^^error^^^^^^^^^^^
....
....

A = my activate MIDlet
B = the form of A.


----debug---
java.lang.NullPointerException
at hello.GUI.keyPressed(+14)
at javax.microedition.lcdui.Canvas.callKeyPressed(+19)
at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+121)
at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+178)
 
B

boki

I have to say sorry.
I declare another Display (but the same name as activate MIDlet) in
GUI.java, your method is funtion work after fixed my bug.

Best regards,
Boki.
 
D

Darryl Pierce

Boki said:
It seems not work on my code...
Even I declare <Main form of activate MIDlet> as public, the GUI.java can't
recognize that symbol.

Mate, this is basic debugging here. It has nothing to do with your use
of the Display.setCurrent() API and is instead a null reference in your
GUI.keyPressed() implementation:

----debug---
java.lang.NullPointerException
at hello.GUI.keyPressed(+14)

What's null in that implementation code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top