File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""identifier expected" error" Watch ""identifier expected" error" New topic

"identifier expected" error

Joe Jones

Joined: Sep 03, 2002
Posts: 3
Hi all, I'm new to java and would like some help figuring out what I'm doing wrong. Here's my code:
package testpackage;

public class Class1 {

public String firstMethod() {
return "My java class!";
package testpackage;

public class Class2 {

Class1 c = new Class1();


Problem is, when Class2 is compiled I'm seeing the following error:
... <identifier> expected

Can someone tell me how I can correct this?

Greg K.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can list a method call like that outside of a method or initializer block. Try putting braces around the line.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Or maybe you wanted to put it in the main() method ?

[ March 02, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
marc weber

Joined: Aug 31, 2004
Posts: 11343

"Greg K.,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: "identifier expected" error
It's not a secret anymore!