aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Code:problem:need to resolve it" Watch "Interface Code:problem:need to resolve it" New topic
Author

Interface Code:problem:need to resolve it

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

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
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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: http://aspose.com/file-tools
 
subject: Interface Code:problem:need to resolve it