Results 1 to 7 of 7
  1. #1
    Cheynems is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Invalid flag problem

    Hello all,

    First post here. I tried searching for a resolution to my problem but could not find anything suitable. If I missed the proper solution, please point me in the right direction and I apologize!

    I recently took up Java as a second programming language to complement my major, and have been diving head first into OOO. I am attempting to compile the guessing game program from head first java, but get an error that the flag is invalid.

    I am running Ubuntu 10.04, and compile/run everything using the terminal. I navigated correctly to the containing folder (everything else has compiled correctly so far).

    The program is a guessing game containing 3 separate class files. One contains the dialog and results for the guessing game, one contains the player class, and one launches the game. According to the tutorial, I am to compile and run the gameLauncher.class file. In the terminal I typed javac gameLauncher.class and am given the following error:

    javac: invalid flag: gameLauncher.class
    Usage: javac<options><source files>
    use -help for a list of possible options

    I have attempted different ways of running this, including leaving out the .class part of the filename, running the class file without compiling first, etc. with no resolution. I know it's probably an easy solution that I am just not recognizing, but I am pretty new to all this. Thanks for any pointers!

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

    Default Re: Invalid flag problem

    I typed javac gameLauncher.class
    The javac program wants a .java file for input.
    Your commandline shows that you are giving it a .class file.

    Use the java command with the name of the class not the filename to start execution of your program:
    java gameLauncher

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

    Default Re: Invalid flag problem

    First you have to compile your java class,

    javac gameLauncher.java
    then only you can run your class,

    java gameLauncher

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

    Default Re: Invalid flag problem

    And by convention, class names start with an uppercase letter. Please read Code Conventions for the Java(TM) Programming Language: Contents

    db
    Last edited by DarrylBurke; 09-15-2011 at 10:32 AM.

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

  6. #6
    Cheynems is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Invalid flag problem

    Eranga - Thank you! Compiling it that way seemed to do the trick, though now I am getting run-time errors. I will sort those out as they happen though (:

    Darryl - With a c++ background thus far, I typically named things with a lowercase for the first word and uppercase for any words after that, within the name. I was not aware that naming conventions for Java were different, but I will keep that in mind. Thank you!

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

Similar Threads

  1. Flag and data passing
    By jack_nutt in forum New To Java
    Replies: 6
    Last Post: 06-10-2011, 01:31 AM
  2. Okay..I'm waiving the white flag on this
    By velvetymold in forum New To Java
    Replies: 10
    Last Post: 02-22-2011, 06:15 AM
  3. Invalid Index
    By Allgorythm in forum New To Java
    Replies: 1
    Last Post: 02-16-2010, 12:51 PM
  4. javac: invalid flag: Files\Java\jdk1.6.0_18;C:\Program
    By darrell22 in forum New To Java
    Replies: 5
    Last Post: 02-09-2010, 08:27 AM
  5. BubbleSorting Problem: invalid method declaration
    By SwEeTAcTioN in forum New To Java
    Replies: 6
    Last Post: 12-02-2009, 03:47 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
  •