Two threads different arguements, eclipse picking the wrong one...

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
Code:
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFileChooser theDirectory = new JFileChooser();
					theDirectory.setMultiSelectionEnabled(false);
					theDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					theDirectory.showOpenDialog(null);
					MyFilter filter = new MyFilter();
					addFiles(theDirectory.getSelectedFile().listFiles(filter));
MyFilter extends FileFilter, but the compiler is complaining about the last line, saying...

Code:
The method listFiles(FilenameFilter) in the type File is not applicable for the arguments 
 (GUI.MyFilter)
It's clearly using the wrong one, but i don't know how to make it use the right method. There are two listFiles methods in the File class.
 
Joined
Sep 12, 2003
Messages
20,583
The method listFiles requires an argument of type FilenameFilter which it appears that the use of the same name Myfilter for a typename and an instance causes the problem.

If filter is not a FilenameFilter, it may not be used as an argument to listFiles.

MyFilter appears to be recursively defined.

-- Tom
 
Joined
Sep 12, 2003
Messages
20,583
The method listFiles requires an argument of type FilenameFilter which it appears that the use of the same name Myfilter for a typename and an instance causes the problem.

If filter is not a FilenameFilter, it may not be used as an argument to listFiles.

MyFilter appears to be recursively defined.

-- Tom
 
Joined
Sep 12, 2003
Messages
20,583
Hi gdi1942,

Right you are about the recursion - I left my declaration syntax somewhere else.

I bow to the manual's definition, however, it looks like there is a restriction for Gui.MyFilter.

-- Tom
 

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
So your saying there is something wrong with my "MyFilter" class, although i can't see what it is, it's extending FileFilter. The only problem i can see is that it's an inner class. I'm currently not at home where my code is, so when i get home i'll repost the entire code block.
 

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
My actionListener
Code:
	private JButton getFolders() {
		if (folders == null) {
			folders = new JButton();
			folders.setText("Add Folder");
			folders.setSize(new Dimension(99, 17));
			folders.setLocation(new Point(104, 383));
			folders.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFileChooser theDirectory = new JFileChooser();
					theDirectory.setMultiSelectionEnabled(false);
					theDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					theDirectory.showOpenDialog(null);
					MyFilter filter = new MyFilter();
					addFiles(theDirectory.getSelectedFile().listFiles(filter));
				}
			});
		}
		return folders;
	}

My Inner class at the bottom of the code

Code:
public class MyFilter extends FileFilter
	{
		public boolean accept (File file)
		{
			if (file.isFile())
			{
				if (file.getName().substring(file.getName().length()-4, file.getName().length()).equalsIgnoreCase(".mp3"))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return true;
			}
		}
		
		public String getDescription ()
		{
			return "MP3 Files";
		}
 
Joined
Jul 29, 2004
Messages
6,650
gdi1942 said:
Code:
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFileChooser theDirectory = new JFileChooser();
					theDirectory.setMultiSelectionEnabled(false);
					theDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					theDirectory.showOpenDialog(null);
					[COLOR=Red][B]MyFilter filter = new MyFilter();[/B][/COLOR]
					addFiles(theDirectory.getSelectedFile().listFiles(filter));
MyFilter extends FileFilter, but the compiler is complaining about the last line, saying...

Code:
The method listFiles(FilenameFilter) in the type File is not applicable for the arguments 
 (GUI.MyFilter)
It's clearly using the wrong one, but i don't know how to make it use the right method. There are two listFiles methods in the File class.
The red bold line may be replaced by :

FileFilter filter = new MyFilter();

as MyFilter is a subclass of FileFilter.
 

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
Genious!! Never thought of that, i'll give it a try when i get home.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top