Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2006-05-08
Medium Priority
Last Modified: 2008-01-09
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 ?

Question by:vikrant_kpr

Expert Comment

ID: 16657155
can u post the code?
LVL 14

Accepted Solution

hoomanv earned 120 total points
ID: 16660422
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) {
            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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question