-1

Hi this is a save function for my program, this is the first time using "file dialog function" it is throwing an error I am not sure how to fix it.

The constructor FileDialog(Frame, String, int) is ambiguous

import java.awt.FileDialog;

public class save {
    private void initialize() {
        FileDialog fileOutputDialog =
            new FileDialog(null, "Output File", FileDialog.SAVE);
    }
}
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Takhata101
  • 29
  • 3
  • 11
  • Fyi, your question is confusing because we don't use the word "throw" when referring to a compile-time problem. – Chris Martin May 19 '14 at 07:06
  • Any particular reason why you decided to use this class instead of [JFileChooser](http://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html)? [How To Use File Choosers](http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html). – predi May 19 '14 at 07:10
  • @Chris Martin: Sorry I'm still kinda new to this forum I was just using "throw" because thats what we use in our discussions about coding in class. But in future I'll be sure to use the proper term! – Takhata101 May 19 '14 at 11:23
  • @Predi I felt it would be easier and cleaner for the future features i need to implement in this code. (choice of encryption between several different forms) – Takhata101 May 19 '14 at 11:26

2 Answers2

1

FileDialog has two constructors of interest for this problem:

public FileDialog(Frame parent, String title, int mode)

public FileDialog(Dialog parent, String title, int mode)

If you call your constructor with a null first argument, how does the compiler know which constructor you want to call?

A better way to handle this would be to declare a variable of the right type, set it to null, and use that as the first argument instead. The static type of that variable allows the compiler to figure out which constructor you want.

For example, if you want the Frame constructor:

Frame unusedFrame = null;
FileDialog fileOutputDialog = new FileDialog(unusedFrame, "Output File", FileDialog.SAVE);
awksp
  • 11,764
  • 4
  • 37
  • 44
1

try this

FileDialog fileOutputDialog = new FileDialog(new Frame(), "Save file", FileDialog.SAVE);

instead of

FileDialog fileOutputDialog = new FileDialog(null, "Output File", FileDialog.SAVE);
Ulaga
  • 863
  • 1
  • 8
  • 17