Results 1 to 4 of 4
  1. #1
    michal5575 is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default invalid method declaration; return type required

    Hi, I tryed to compile this:
    package HelloWorld;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    /**
    * @author michal5575
    */
    public class Midlet extends MIDlet {
    private Display display = null;

    private TextBox tbMainForm;

    public MIDlet(){
    tbMainForm = new TextBox("My First MIDlet","Hello World !",100,0);
    }

    public void startApp() {
    if(display==null)
    display = Display.getDisplay(this);
    display.setCurrent(tbMainForm);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    }


    And i get this error:

    invalid method declaration; return type required
    public MIDlet(){

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: invalid method declaration; return type required

    I don't really mess with micro edition, but don't you still need a public static void main(String args[])?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default Re: invalid method declaration; return type required

    First things first, please use the [CODE] tags when posting code.

    Take a look at the following block:

    Quote Originally Posted by michal5575 View Post
    public MIDlet(){
    tbMainForm = new TextBox("My First MIDlet","Hello World !",100,0);
    }
    Is that suppose to be a Constructor for the Midlet class? If so there is something wrong there... (Hint: 1st Line of the following Tutorials Providing Constructors for Your Classes)

  4. #4
    michal5575 is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: invalid method declaration; return type required

    Ok thx compilled successfuly. I used this code:

    Java Code:
    Test;
    
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    public class Midlet extends MIDlet implements CommandListener {
    
        private Display display;
        private TextBox textBox;
        private Command quitCommand;
    
        public void startApp() {
            display = Display.getDisplay(this);
            quitCommand = new Command("Quit", Command.SCREEN, 1);
            textBox = new TextBox("Hello World", "Looks different in Mobile", 40, 0);
            textBox.addCommand(quitCommand);
            textBox.setCommandListener(this);
            display.setCurrent(textBox);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
        }
    
        public void commandAction(Command choice, Displayable displayable) {
            if (choice == quitCommand) {
                destroyApp(false);
                notifyDestroyed();
            }
        }
    }

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2012, 08:33 PM
  2. invalid method declaration; return type required
    By DeclareVariablesNotWar in forum New To Java
    Replies: 10
    Last Post: 12-13-2011, 02:57 AM
  3. Replies: 2
    Last Post: 08-23-2011, 10:43 PM
  4. Invalid Method Declaration; Return Type Required
    By bremzb in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2011, 10:12 PM
  5. invalid method declaration; return type required
    By XaviannNJ in forum JCreator
    Replies: 7
    Last Post: 11-25-2010, 01:59 PM

Posting Permissions

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