• Post Reply Bookmark Topic Watch Topic
  • New Topic

javac: Invalid flag  RSS feed

 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

So today i was trying to compile a simple script that used to work before on Sublime Text 2, an i got the following error;

javac: invalid flag:
Usage: javac <options> <source files>
use -help for a list of possible options
I already know the script works because i didn't change anything since the last time it work, but anyways just in case i tried running a HelloWorld program just to check it out and i got the same error. The i stop trying to compiling the HelloWorld on Sublime so I went to Terminal and i got the same exact error.
HELp?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the command/script look like exactly?
 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
}
}

EVERYTIME try to build it in Sublime Text 2 i get the following error;

javac: invalid flag:
Usage: javac <options> <source files>
use -help for a list of possible options
[Finished in 0.2s with exit code 2]

I don't know why this is happening when before i was able to build java programs in Sublime with no problem whatsoever now i get the error i said above. Sublime is also not letting me save any of my files, Everytime i click save it prompts the following;

Unable to save /HelloWorld.java

But then when i try to compile a HelloWorld.java file on Terminal it gives the following errors;

new.java:1: error: <identifier> expected
public class new{
^
new.java:2: error: illegal start of expression
public static void main(String []args){
^
new.java:2: error: illegal start of expression
public static void main(String []args){
^
new.java:2: error: ';' expected
public static void main(String []args){
^
new.java:2: error: '.class' expected
public static void main(String []args){
^
new.java:2: error: ';' expected
public static void main(String []args){
^
new.java:6: error: reached end of file while parsing
}
^
7 errors
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what - EXACTLY - are you typing to compile this?

It just worked for me with no issues.
 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In terminal all im typing is:

javac new.java

and then i get all of these errors;

new.java:1: error: <identifier> expected
public class new{
^
new.java:2: error: illegal start of expression
public static void main(String []args){
^
new.java:2: error: illegal start of expression
public static void main(String []args){
^
new.java:2: error: ';' expected
public static void main(String []args){
^
new.java:2: error: '.class' expected
public static void main(String []args){
^
new.java:2: error: ';' expected
public static void main(String []args){
^
new.java:6: error: reached end of file while parsing
}
^
7 errors

For sublime all I'm doing is to click on Build and yes i do have the java build system selected (:
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Vargas wrote:In terminal all im typing is:

javac new.java


and then i get all of these errors;

new.java:1: error: <identifier> expected
public class new{
^



"new" (all in lower case) is a Java keyword. I don't think that you can name a class with that name.

Henry
 
Daniel Vargas
Greenhorn
Posts: 17
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OHH that makes a lot of sense Henry thank you.

But i still can't figure out why Sublime Text won't let me build this

public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
}
}

It always gives this error whenever i try to build it and i made sure of having the Java build system selected before building;

javac: invalid flag:
Usage: javac <options> <source files>
use -help for a list of possible options
[Finished in 0.2s with exit code 2]

Sublime Text also won't let me save my file, whenever i try saving it only prompts this:

Unable to save /HelloWorld.java
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Vargas wrote:It always gives this error whenever i try to build it and i made sure of having the Java build system selected before building;

javac: invalid flag:

Somewhere in Sublime Text 2 there will be a way to set the java compiler options. I've never used it so I can't tell you where, but you need to find it and see what options are set. One of them is not a valid option.

Edit: Okay. I was assuming Sublime Text was an IDE, but it appears to be just a text editor that you can configure to compile and run java code. But that configuration doesn't look easy.
You might want to ask for this post to be moved to the IDEs, Version Control and other tools forum, where there may be someone who knows a bit more about Sublime Text
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with Sublime Text. You might do well to try another editor and use the command line instructions directly.
I shall take up Joanne's suggestion and duplicate this thread in the IDEs forum.
 
Ben Dobson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at what you have pasted your [] has a gap, perhaps placing this after String - String[] args.

Before:



After:



Perhaps the compiler doesn't like it?

N
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Dobson wrote:Perhaps the compiler doesn't like it?

The Java compiler is very forgiving when it comes to the []s. All these will compile fine:
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But only one is correct style
There are recommendations about the main method in the Java Language Specification.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!