This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes 'void' type not allowed here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " Watch " New topic
Author

'void' type not allowed here

Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65


I am getting that 'void type not allowed here' highlighting that first 'else if' line.

I clicked on the ? in BlueJ but it wasn't very informative. I don't even know what a void type is? Did I use null incorrectly? I have never used it before.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
Could it be that your changeCurrentlyRentedReturn() method is declared as void?
Also, this code looks suspect:

else if (currentMovie.changeCurrentlyRentedReturn() == true) {
currentMovie.changeCurrentlyRentedReturn();
}

You're calling a method, and when you know what it returns, you call it again?
[ August 07, 2005: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65
But I don't know what it returns, except that it could be true or false.
Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65
Oh wait...I just looked at it again...I'm going back to my code....
Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65


I called the wrong method but it is corrected here...but I am still getting the void error.
Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65
OHHHHHHH...and the light clicks on!!!

I get what it means now! I was just looking at the class from the method I was calling and both those methods are "public void...". The method I need to call needs to have a boolean type!

Is that what you meant?
Lisa Beglaw
Ranch Hand

Joined: Jul 16, 2005
Posts: 65
K...I changed it and now it compiles....now to test!
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
Just a minor style point, but the true in those if statements is implicit, so you can replace this:

if (currentMovie.changeCurrentlyRentedOut() == true) {

with this:

if (currentMovie.changeCurrentlyRentedOut()) {


Also you can just use the negation operator instead of comparing to false (though it could be argued that false might be easier to read in some situations):

if (currentMovie.changeCurrentlyRentedOut() == false) {

replace with:

if (!currentMovie.changeCurrentlyRentedOut()) {
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'void' type not allowed here
 
Similar Threads
Void type not allowed
Duplicate print lines but I only want it once
Missing a ')' somewhere...
Else without an if
To use break statements or not to use break statements, that is the question