I get an error message when trying to use my component installed to the palette!

Note: Read first How to use a component... to learn how to install the component to the palette.

There can be several reasons why a custom component does not work (error occurs when trying to add it from palette to a form). There are 2 types of errors.

1. The error message complains that it cannot load the component class and says something about classpath. In this case check where the component comes from.

  • If the component has been installed from a JAR file then check the JAR file is there and nothing bad happened to it. The same for installing from a library (check the JARs it uses really exist).
  • Also check if the component does not actually require more JARs, not just the one it was installed from. In such case it would be better to define a library which can cover more JARs as a single unit. Do this in the Library Manager available from Tools menu. Then remove the component from palette and install it again - from the library.
  • If the component has been installed from a project then make sure the component is compiled, or better, the whole project is built. To be sure invoke Clean and Build on the project. Sometimes an old built JAR might be around without your new component yet.
  • If you have sources of the component, make sure the package declaration is correct - that it corresponds to the directory the file is located in the resulting JAR.
  • If you list the available JavaBeans in the manifest.mf file of the component's JAR, make sure you specify the full path within the JAR for the class file of the component, not just the class file itself. If you find this is wrong then correct it, remove the component from palette, and install it again from the fixed JAR.

2. The error message says that the component cannot be instantiated and that you should make sure it is a JavaBean. In this case the class can be found and loaded, but an instance can't be created.

  • Yes, check the component is really a JavaBean. It means the class can't be abstract, must be public, must have a public constructor without parameters, and this constructor must not fail (throw any exception).
  • If you provide a BeanInfo with your component then make sure the BeanInfo is up-to-date (not failing e.g. because referring to some non-existing method in the bean class).
  • Also check what the component is doing when constructed. Mainly if it does not refer to some unavailable resource (e.g. icon), or rely on something which is normally available in your application but not if the bean is instantiated standalone. A failure on NullPointerException is typical in such case.
  • Make sure that your JavaBeans is subclass of JPanel, not JFrame.

It is always a good idea to consult the NetBeans log file where you find the exact stack trace of the exception causing the failure. The top lines of the last stack trace in the file will likely belong to your component. The log can be shown from menu View | IDE Log. The log file itself is located in: userdir /var/log/messages.log

  Applies to: NetBeans 5.0, 5.5, 6.x
  Platforms: All
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo