Take the 2-minute tour ×

I have two different workspaces. In each of them I have source folder ch17 and package cont in each of the folders. I have coded a simple class (below) in first workspace and it compiles and runs just fine. However when I try to run it in another workspace I get error

Could not find the main class: cont.DirList. Program will exit

I have checked the source folder (on disc) and this class is there. I have even compiled it from the command line, but it doesn't help. Classes that were in this workspace compile and run just ok. However when I try to add new class to this source folder it displays the same error. I also tried to add same class to a different source folder but then it displays same error. I tried to delete this folder and add it once again, refresh it, restart eclipse, etc. but there is still error.

What is wrong and how to fix it?

package cont;

import java.util.regex.*;
import java.io.*;
import java.util.*;

public class DirList {

  public static void main(String[] args) {
    File path = new File(".");
    String[] list;
    if(args.length == 0)
      list = path.list();
      list = path.list(new DirFilter(args[0]));

    Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
    for(String dirItem : list)

class DirFilter implements FilenameFilter {
  private Pattern pattern;
  public DirFilter(String regex) {
    pattern = Pattern.compile(regex);

  public boolean accept(File dir, String name) {
    return pattern.matcher(name).matches();
} /* Output:


share|improve this question
In your Eclipse project, is cont marked as your source folder? Or is cont immediately under the folder you have marked as your source folder? It needs to be the latter. –  highlycaffeinated Apr 5 '12 at 13:44
cont is a package (sorry for mistake) and ch17 is a source folder. Same hierarchy I have for other classes in this workspace and everything works fine. –  aretai Apr 5 '12 at 13:45
I am currently having the same problem. –  Jared Burrows Jun 6 '12 at 20:41

Your Answer



Browse other questions tagged or ask your own question.