• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

'void' type not allowed here

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K...I changed it and now it compiles....now to test!
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()) {
 
reply
    Bookmark Topic Watch Topic
  • New Topic