问题
I'm trying to declare a java.awt.FileDialog in my code:
FileDialog save = new FileDialog(null, "Save file", FileDialog.SAVE);
But I get the following error in my console when I try to run my code:
The constructor FileDialog(Frame, String, int) is ambiguous
Anyone know what I am doing wrong?
回答1:
There are 2 constructors for FileDialog with 3 arguments. Because you passed null as the first argument, the compiler cannot distinguish which constructor you want.
FileDialog(Dialog parent, String title, int mode)
and
FileDialog(Frame parent, String title, int mode)
You could use:
Frame frame = null;
FileDialog save = new FileDialog(frame, "Save file", FileDialog.SAVE);
to fix.
来源:https://stackoverflow.com/questions/12165653/error-when-declaring-java-awt-filedialog