• Post Reply Bookmark Topic Watch Topic
  • New Topic

error: 'void' type not allowed here  RSS feed

 
Ivan Addeo
Ranch Hand
Posts: 52
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!