File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compilation error" Watch "Compilation error" New topic
Author

Compilation error

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305


Client.java: error: 'void' type not allowed here
System.out.println(" "+((MenuComponent)iterator.next()).print());

My one regret in life is that I am not someone else.
- Woody Allen
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38840
    
  23
The print method returns “void”. And you are passing void to the + operator.

Did you want to pass a String? In which case you should’t pass the print() method. You should specify that String in the toString() method and miss out the print() call.
[You can also miss out the nasty cast, and use polymorphism.]

You ought to declare the Iterator as Iterator<MenuComponent>, then you won’t need casts at all.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38840
    
  23
OR:Because of polymorphism, that will work irrespective of the types in the List.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38840
    
  23
And you will have lots more compiler errors unless your spelling is better than mine
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7793
    
  21

meeta gaur wrote:Client.java: error: 'void' type not allowed here
System.out.println(" "+((MenuComponent)iterator.next()).print());

Meeta,

Simply posting a piece of code with an error message is useless.

What is your question?

Do you not understand the error message? Because if not, you really need to go back to the tutorials and re-read about methods and return types.

And if it's something else, you need to TellTheDetails.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Thank you Campbell
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation error