J2ME, Canvas,

Discussion in 'Java' started by Boki, Mar 23, 2005.

  1. Boki

    Boki Guest

    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.
    Boki, Mar 23, 2005
    #1
    1. Advertising

  2. Boki wrote:
    > 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...

    --
    Darryl L. Pierce <>
    Visit my homepage: http://mcpierce.multiply.com
    "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Darryl Pierce, Mar 24, 2005
    #2
    1. Advertising

  3. Boki

    Boki Guest

    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.

    "Darryl Pierce" <>
    ???????:0Uy0e.51704$...
    > Boki wrote:
    >> 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...
    >
    > --
    > Darryl L. Pierce <>
    > Visit my homepage: http://mcpierce.multiply.com
    > "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Boki, Mar 24, 2005
    #3
  4. "Boki" <> writes:

    > 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?
    Tor Iver Wilhelmsen, Mar 24, 2005
    #4
  5. Boki

    Boki Guest

    sure, do you mean

    when I press a soft button
    and that perform:

    display.setCurrent( Main form ) ?

    Best regards,
    Boki.

    "Tor Iver Wilhelmsen" <>
    ???????:...
    > "Boki" <> writes:
    >
    >> 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?
    Boki, Mar 24, 2005
    #5
  6. Boki wrote:
    > 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?

    --
    Darryl L. Pierce <>
    Visit my homepage: http://mcpierce.multiply.com
    "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Darryl Pierce, Mar 26, 2005
    #6
  7. "Boki" <> writes:

    > when I press a soft button
    > and that perform:
    >
    > display.setCurrent( Main form ) ?


    Yes.
    Tor Iver Wilhelmsen, Mar 26, 2005
    #7
  8. Boki

    Boki Guest

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

    Thank you very much.

    Best regards,
    Boki.

    "Tor Iver Wilhelmsen" <>
    ???????:...
    > "Boki" <> writes:
    >
    >> when I press a soft button
    >> and that perform:
    >>
    >> display.setCurrent( Main form ) ?

    >
    > Yes.
    Boki, Mar 26, 2005
    #8
  9. Boki wrote:
    > 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.

    --
    Darryl L. Pierce <>
    Visit my homepage: http://mcpierce.multiply.com
    "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Darryl Pierce, Mar 26, 2005
    #9
  10. Boki

    Boki Guest

    I got it!

    Thank you a lot !

    Best regards,
    Boki.

    "Darryl Pierce" <>
    ???????:pOb1e.67781$...
    > Boki wrote:
    >> 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.
    >
    > --
    > Darryl L. Pierce <>
    > Visit my homepage: http://mcpierce.multiply.com
    > "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Boki, Mar 26, 2005
    #10
  11. Boki

    Boki Guest

    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)


    "Tor Iver Wilhelmsen" <>
    ???????:...
    > "Boki" <> writes:
    >
    >> when I press a soft button
    >> and that perform:
    >>
    >> display.setCurrent( Main form ) ?

    >
    > Yes.
    Boki, Mar 27, 2005
    #11
  12. Boki

    boki Guest

    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.

    "Boki" <> wrote in message news:<d26pbu$ddm$>...
    > 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)
    >
    >
    > "Tor Iver Wilhelmsen" <>
    > ???????:...
    > > "Boki" <> writes:
    > >
    > >> when I press a soft button
    > >> and that perform:
    > >>
    > >> display.setCurrent( Main form ) ?

    > >
    > > Yes.
    boki, Mar 28, 2005
    #12
  13. Boki wrote:
    > 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:

    <snip>

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


    What's null in that implementation code?

    --
    Darryl L. Pierce <>
    Visit my homepage: http://mcpierce.multiply.com
    "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
    Darryl Pierce, Mar 28, 2005
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mchmiel
    Replies:
    2
    Views:
    3,781
    Tim Tyler
    Jul 5, 2003
  2. Oz Mortimer

    J2ME scrolling canvas?

    Oz Mortimer, Sep 17, 2003, in forum: Java
    Replies:
    6
    Views:
    8,863
    Darryl L. Pierce
    Sep 19, 2003
  3. Askari
    Replies:
    2
    Views:
    693
    Askari
    Aug 30, 2004
  4. PhilC
    Replies:
    2
    Views:
    864
    PhilC
    Oct 25, 2004
  5. Replies:
    10
    Views:
    244
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page