Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'void' type not allowed here

 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I don't know what it returns, except that it could be true or false.
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wait...I just looked at it again...I'm going back to my code....
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I called the wrong method but it is corrected here...but I am still getting the void error.
 
Lisa Beglaw
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K...I changed it and now it compiles....now to test!
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()) {
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic