Issue
When I try to compile this:
import java.awt.* ;
class obj
{
public static void printPoint (Point p)
{
System.out.println ("(" + p.x + ", " + p.y + ")");
}
public static void main (String[]arg)
{
Point blank = new Point (3,4) ;
System.out.println (printPoint (blank)) ;
}
}
I get this error:
obj.java:12: 'void' type not allowed here
System.out.println (printPoint (blank)) ;
^
1 error
I don't really know how to start asking about this other than to ask:
- What went wrong here?
- What does this error message mean?
Solution
If a method returns void
then there is nothing to print, hence this error message. Since printPoint already prints data to the console, you should just call it directly:
printPoint (blank);
Answered By - Justin Ethier
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)