aspose file tools*
The moose likes Beginning Java and the fly likes <indentifier> expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "<indentifier> expected" Watch "<indentifier> expected" New topic
Author

<indentifier> expected

Rob Sweeny
Greenhorn

Joined: Jan 14, 2010
Posts: 16
Hi All,

Happy to find a newbe friendly forum!

I've got my code to be real simple but it still is giving me problems.

I'm trying to create and use a class outside of my main class.

Main Class: GreetingsUniverse

package com.scjaexam.tutorial;
//import com.scjaexam.tutorial.planets.*;

public class GreetingsUniverse {
public static void main(String[] args) {
System.out.println("Greetings, Universe!");
Earth e = new Earth();
Mars e = new Mars();
Veuns e = new Venus();

}
}

Other Class: Earth

package com.sjcaexam.tutorial;

public class Earth {
public Earth {
System.out.println("Hello from Earth");
}
}


javac GreetingsUniverse.java

results in:

.\com\scjaexam\tutorial\Earth.java:4: <identifier> expected
public Earth {
^


Any help would be greatly appreciated.
Thanks
Rob
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Try:




Also, when you post code, please use code tags. You can find the Code button along the top of the box where you post your message body. Thanks!


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Rob Sweeny
Greenhorn

Joined: Jan 14, 2010
Posts: 16
Main Class: GreetingsUniverse



Other Class: Earth



javac GreetingsUniverse.java

results in:

.\com\scjaexam\tutorial\Earth.java:4: <identifier> expected
public Earth {
_________^


Any help would be greatly appreciated.
Thanks
Rob
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You saw that the question was answered, correct? (Although normally we try to provide hints rather than absolute solutions.)
Rob Sweeny
Greenhorn

Joined: Jan 14, 2010
Posts: 16
Thanks for the quick responses!

Now I have the same error on a different line

Could it have something to do with packaging?


Main Class: GreetingsUniverse



Other Class: Earth



c:\code>javac GreetingsUniverse.java
.\com\scjaexam\tutorial\Earth.java:4: <identifier> expected
System.out.println("Hello from Earth");
______________^

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Nope. Now you're trying to write non-initialization code outside of any method.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
David Newton wrote:You saw that the question was answered, correct? (Although normally we try to provide hints rather than absolute solutions.)


You're right. That was my mistake.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@W Joe Smith: No problem; just a handy reminder ;) I have a towel signed by Douglas Adams.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
David Newton wrote:@W Joe Smith: No problem; just a handy reminder ;) I have a towel signed by Douglas Adams.


Bah! I wish I had that.....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
And welcome to JavaRanch
Rob Sweeny
Greenhorn

Joined: Jan 14, 2010
Posts: 16
And welcome to JavaRanch


Happy to be here.

i found the problem.


Original code:



created <identifier> expected error

Fixed Code:



the identifier that was expected was () to make this code into a proper constructor.

Thanks Everyone
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Actually, no, the "proper identifier" is the method, not the empty parameter list.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <indentifier> expected