aspose file tools*
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
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: 42289
    
  64
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 - my free Android networking tools app
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()) {
 
 
subject: 'void' type not allowed here