Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
The Main method should read
Try that and see if that helpspublic static void main(String[] args)
If not, what error are you getting?
change the class name 'a' to 'A' it will wrks
class A
The error is due to the ar it must be args. -As samfin said.
Correct it, ur code will be working even if its class a or class A or class whatever
This is absolutely not true. All of the following work fine:
class Main { public static void main(String[] ar){ System.out.println("Works"); } }
class Main { public static void main(String[] iLikeCats){ System.out.println("Works"); } }
class Main { public static void main(String... a){ System.out.println("Works"); } }
Run them and see. Seriously, what's with posting help that is actually completely wrong?
Chances are, the OP was trying to compile a class with the wrong name- such as A.java instead of a.java, or vice versa.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
copeg (January 20th, 2011), javapenguin (January 20th, 2011), JavaPF (January 20th, 2011)
lol @ iLikeCats
rahul dixit, please post the error you are getting or attach a screenshot.
Thanks
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
then y did his code didn't compile if it's correct ??
By the way thanks i dnt knw that we can give anything after String[].
His code didn't compile because, presumably, he was trying to compile a class that didn't exist.
Say his file was named a.java- Putting aside the fact that class names should start with a capital letter and be more meaningful than a single character.
He then tried to compile A.java. That's not the same as a.java. A != a. Just like he couldn't compile iReallyLikeCats.java, if his file was actually named iLoveCatsSoMuch.java.
Simple as that.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
But he has stated that
I COMPILE THIS BY- javac a.java and run by- java a
so probably it must work. rite ??
He also typed the error message in all caps, eliminating any assurances that the error is talking about a.java and not A.java or A.JAVA or A.jAvA.
There is also the likelihood that he didn't copy and paste the error, or the file names, into the forum editor exactly. There is just too much uncertainty, which is why we're waiting on clarification from the OP. But until (if) that happens, I'd be willing to bet that he spelled the file name wrong, probably by using the wrong case.
Because the error he's talking about isn't a compiler error. It's an error saying that the specified file could not be found, let alone compiled. Even if the main(String [] args) error you guys erroneously came up with was real, the compiler didn't even get a chance to see that yet, since it has not been given a valid file name.
If it worked, why would he have posted in the first place?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
so probably it must work. rite ??
What i meant is if he had ran the prg using the correct classname it would have worked.
Assumptions apart. Lets wait if he provides any OP. From that we can conclude what went wrong.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Then lets conclude he had used a wrong file name
It wasn't my intent to deliberately post something that was wrong. Admittedly I could have checked the fact before posting but in every code example I've ever seen it is put as public static void main(String args[]) and seeing it differently there seemed wrong and it never occured to me that it could be something else.
Anyway, I've learned something today which is why I joined this forum in the first place.
I think the thread creator should go through this.
How to ask question ?l
and i request admin to create a page for which question should be answer ?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!