0

Dear friends,
I have a piece of code that looks like this:
JOptionPane.showMessageDialog(null,"List of Tax Payers for year 2006 (Sorted with NRIC):" + printList() );

However, the compile error was this:
'void' type not allowed here
case 1 : JOptionPane.showMessageDialog(null,"List of Tax Payers for year 2006 (Sorted with NRIC):" +printList() );

my intention was to print the results computed inside printList(); found under the driver file but I can't do that.

If I were to use System.out.println("Results are " + printList() ); can work but why can't it work under JOptionPane??

Thanks in advance!

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by masijade
0

What does printList() do?

From that error messages, and the rest you've said about it, I can only assume that it has a return type void, and that it makes calls to System.out.println() itself, to produce the output.

Well, you can't do it that way. Have the method simply build a String (rather than outputting it directly) and then return that String from the method. Then it should "work" in both instances.

If all that is the case, then I need to ask how you thought that something was being output directly to the standard output stream would show up in the JOptionPane? Did you think it would happen simply because you placed the call to the method inside of a call to JOptionPane?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.