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 Interface Code:problem:need to resolve it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Code:problem:need to resolve it" Watch "Interface Code:problem:need to resolve it" New topic

Interface Code:problem:need to resolve it

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 561

Hi Ranchers,
I have the below Java code.

Im compiling this program as below and getting the error as shown below.
why am i getting the below error <identifier> expected.

Please guide me /suggest me whats wrong with the above piece of code.

Help provided will be highly appreciated.

Deepak Lal

When The Going Gets Tougher,The Tougher gets Going
Ankit Garg

Joined: Aug 03, 2008
Posts: 9453

You are trying to initialize a field in the class body. This is not allowed in a separate statement. Either move it with the declaration or move it into an initializer block

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rob Spoor

Joined: Oct 27, 2005
Posts: 20194

This has nothing to do with the interface. The problem is that you are trying to put statements outside of a method or (static) initializer.

Remember, all a class can contain are declarations (fields, constructors, methods, inner classes / interfaces / enums) and (static) initializer blocks. Any regular code does not belong there.

You can quite easily fix your code by combining the declaration and statement into one:

How To Ask Questions How To Answer Questions
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 561

Thanks for your valuable input and efforts for fixing this piece of code.
Thanks Ankit and Rob.

Deepak Lal
I agree. Here's the link:
subject: Interface Code:problem:need to resolve it
It's not a secret anymore!