• 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

error: 'void' type not allowed here

 
Ranch Hand
Posts: 52
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! I'm new on the site and i'm studying with the Thinking in Java. I've a doubt with a program.

This work perfectly (is the solution of an exercisce):



This is my program:



It doesn't work.. the error is:

Testing.java:11: error: 'void' type not allowed here
System.out.println(Test.increment());


Why it doesn't work?
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println is used to print something out. But what are you trying to print? Your Test.increment() class returns void. If it could return something your code would be fine, but it can't print the absence of a value.

You'll note that in the original version it never tries to print the return value of the increment() method.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch! You are at the right place to learn!
 
Ivan Addeo
Ranch Hand
Posts: 52
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:System.out.println is used to print something out. But what are you trying to print? Your Test.increment() class returns void. If it could return something your code would be fine, but it can't print the absence of a value.

You'll note that in the original version it never tries to print the return value of the increment() method.



Oh, it's true. Thanks for your help!

How can i multi-quote many replies?

@Joe Harry: Thanks, i like a lot this forum!
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Addeo wrote:How can i multi-quote many replies?


Use the methodology invented by the greatest inventor of all time. His name is Copy Paste.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic