Results 1 to 8 of 8
  1. #1
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Question How do i call display.setcurrent

    Hi. I have the midlet class like this in a.java
    public class a extends MIDlet{
    ....
    }

    now i want to create a static method in this class for changing the current display. How do i do that?
    Static Display k= new Display.getDisplay() gives an error
    . Please dont just give me links.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    gives an error
    Please copy and paste the full text of the error message.

  3. #3
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Default

    error- non-static variable cannot be referenced from a static method

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Default

    how? i cant make a new iinstance of a MIDlet, since it will give a security error. and i need to call the display.setcurrent from another class. how can i do that if the methos is not made static?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Quote Originally Posted by arnab321 View Post
    Hi. I have the midlet class like this in a.java
    public class a extends MIDlet{
    ....
    }

    now i want to create a static method in this class for changing the current display. How do i do that?
    Static Display k= new Display.getDisplay() gives an error
    . Please dont just give me links.
    the keyword new is used in conjunction with a constructor. not with a static method. This is how you get a reference to the Display associated with a currently running MIDlet from within the class:
    Java Code:
    Display display = Display.getDisplay(this);
    This cannot be executed in a static method or block as it references the instance alias this.

    db
    Last edited by DarrylBurke; 11-04-2008 at 12:09 PM.

  7. #7
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Default

    ok, then plz suggest me another method to call "Display display = Display.getDisplay(this);" from a class outside the midlet class.
    if the midlet class is like:class a extends MIDlet{} can i replace "this" with something else, like the class name so that i can use it from an outside class?

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Quote Originally Posted by arnab321 View Post
    ok, then plz suggest me another method to call "Display display = Display.getDisplay(this);" from a class outside the midlet class.
    Three ways:
    1) Pass a reference to the MIDlet to the constructor of the other class
    2) Pass a reference to the MIDlet's Display.getDisplay(this) to the constructor of the other class
    3) Provide a method in your MIDlet that returns Display.getDisplay(this)

    if the midlet class is like:class a extends MIDlet{} can i replace "this" with something else, like the class name so that i can use it from an outside class?
    No. Read the API.

    db

Similar Threads

  1. Replies: 0
    Last Post: 06-28-2008, 09:26 PM
  2. How to call the input value from different file?
    By xiongling in forum Networking
    Replies: 6
    Last Post: 04-07-2008, 10:05 AM
  3. how to call a dll from java
    By katie in forum Advanced Java
    Replies: 3
    Last Post: 12-10-2007, 10:34 AM
  4. I need to call and run another program
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 05:47 AM
  5. How To Call EJB From Eclipse IDE
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •