Error when declaring java.awt.FileDialog

流过昼夜 提交于 2019-12-20 03:12:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!