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!

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.