thread "main" java.lang.Error: factory already defined

I Have created a Java program in which i am calling  the function
url.setURLStreamHandlerFactory(hh); i get the following error.
thread "main" java.lang.Error: factory already defined.

Can someone please suggest as to why the error is coming & how to resolve the same ?

Regards
vikrant_kprAsked:
Who is Participating?
 
hoomanvCommented:
looking at the source code of URL.java
you'll find that this error will be thrown when factory is already defined (factory != null)

public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
      synchronized (streamHandlerLock) {
            if (factory != null) {
                  throw new Error("factory already defined");
            }
            SecurityManager security = System.getSecurityManager();
            if (security != null) {
                  security.checkSetFactory();
            }
            handlers.clear();
            factory = fac;
      }
}

due to the java documentation:
This method can be called at most once in a given Java Virtual Machine.
because factory is a Class member (not instance member) declared as: static URLStreamHandlerFactory factory
0
 
avinthmCommented:
can u post the code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.