Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Moose Greetings  RSS feed

 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I realise that this will have come up before but I am not sure what to search for.

I have installed Java 1.6.0_24 and set my Paths (I think) I have followed the instructions for Moose Greetings (http://www.coderanch.com/how-to/java/how-to-create-java-program) When I compile I get an error stating:

MooseGreetings.java:1: class MooseGreeting is public, should be declared in a file named MooseGreeting.java
public class MooseGreeting {


Please could someone let me know what I am doing wrong, the text was copied from the webpage.

Many thanks
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Strange wrote:
MooseGreetings.java:1: class MooseGreeting is public, should be declared in a file named MooseGreeting.java
public class MooseGreeting {


Did you follow what the compiler error states?

And Welcome to JavaRanch
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really new to this and don't really understand what it says.

Sorry to be a pain
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me help you out: What is the name of the file you are trying to compile?
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought I should post my code.

public class MooseGreeting {
public static void main(String[] args) {
System.out.println("moooooooo");
}
}
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MooseGreetings.java
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the class is public- The file name containing the public class should have similar name as that of the public class name. In this case it should be MooseGreeting.java
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Strange wrote:MooseGreetings.java

Your class is MooseGreeting, but your file name is MooseGreetings (an extra "s")
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silly mistake, thank you.

 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Strange wrote: . . . Sorry to be a pain
You're not. Everybody makes that sort of mistake.

But you would have got the answer quicker if you'd given us more details, in this case the file name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!