• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

<indentifier> expected

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Rob Sweeny
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You saw that the question was answered, correct? (Although normally we try to provide hints rather than absolute solutions.)
 
Rob Sweeny
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope. Now you're trying to write non-initialization code outside of any method.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@W Joe Smith: No problem; just a handy reminder ;) I have a towel signed by Douglas Adams.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.....
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Rob Sweeny
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, no, the "proper identifier" is the method, not the empty parameter list.
 
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic