Could not find Class Loader in java

I am running the following code in My Eclipse ...

package foo;

public class Test
{
    public static void main(String[] args)
    {
        ClassLoader loader = Test.class.getClassLoader();
        System.out.println(loader.getResource("foo/Test.class"));
    }
}

But I get o / p as null on the console.

Help me..

+4
source share
1 answer

Use the following code to find out where the class loader will load. The following code worked for me in an empty project .

public class Test {

        public static void main(String[] args)
        {
            URLClassLoader loader = (URLClassLoader) Test.class.getClassLoader();

            System.out.println(Arrays.toString(loader.getURLs()));

            System.out.println(loader.getResource("foo/Test.class"));
        }
}
  • Make sure there are no errors in the workspace.

  • See if the file exists in the view Navigator.

  • Try cleaning the project once.

+1
source

All Articles