1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by gdi1942, Jun 28, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. gdi1942

    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.
     
  2. lotuseclat79

    lotuseclat79

    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
     
  3. lotuseclat79

    lotuseclat79

    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
     
  4. gdi1942

    gdi1942 Thread Starter

    Joined:
    Nov 1, 2006
    Messages:
    215
  5. lotuseclat79

    lotuseclat79

    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
     
  6. gdi1942

    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.
     
  7. gdi1942

    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";
    		}
     
  8. Chicon

    Chicon

    Joined:
    Jul 29, 2004
    Messages:
    6,650
    The red bold line may be replaced by :

    FileFilter filter = new MyFilter();

    as MyFilter is a subclass of FileFilter.
     
  9. gdi1942

    gdi1942 Thread Starter

    Joined:
    Nov 1, 2006
    Messages:
    215
    Genious!! Never thought of that, i'll give it a try when i get home.
     
  10. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/589732

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice