This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compilation error!" Watch "Compilation error!" New topic

Compilation error!

Shamsudeen Akanbi
Ranch Hand

Joined: Dec 24, 2010
Posts: 71
Hi ranchers, I don't understand why I get an error each time i compile this code.

The compilation error is:
C:\Test>javac error: 'void' type not allowed here
while(count < an.getSentinel()) {
1 error
Jan Cumps

Joined: Dec 20, 2006
Posts: 2491


your getSentinel() has a return value of type void (this means, it does not return anything.)

Then you try to compare that return value to an int.
That is impossible. You can't compare an int to a void. You can't compare a void to nothing else, because it represents 'nothing'.

Regards, Jan

OCUP UML fundamental and ITIL foundation
youtube channel
Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

Did you try reading the error message? It's telling you exactly what's wrong, and it's a straightforward message.

It's pointing at your "while" condition and telling you that you can't use void there. You understand why, right? If you have while(X < Y), then X and Y must both be numerical values. You know that, right? So, it's pointing at that and complaining about something being void. You should be able to figure out what is void there.

And now that you know that, it should be obvious why it's an error.

Shamsudeen Akanbi
Ranch Hand

Joined: Dec 24, 2010
Posts: 71
Ouch! I got that. Thank you guyz.
I agree. Here's the link:
subject: Compilation error!
Similar Threads
How to solve socket mistake
String Tokenizer
Splitting an input string whilst storing its value beyond a block of code
How to get name of 2D matrix as user input?
Program example using KeyboardReader