|Thrown when an application tries to call an abstract method. Normally, this error is caught by the
compiler. It could occur at run time only if the callee were modified to make
the method or enclosing class abstract without
recompiling both caller and callee.|
- This usually happens in unsigned Applets when you attempt to do something Applets are not allowed to do, such as read a file or talk
to a server other than the one you were loaded from. You are getting
slapped down by the security sandbox. However, they also occur in other
contexts you would not think would be related to security, e.g. in
RMI (Remote Method Invocation)
when you have a mangled serialised object, or if you try to register a
Oracle bug number 4809366
: The Bea JVM fails to give permission for getClassLoader
even when you ask for AllPermissions
- One common way to get in trouble is to use absolute URL (Uniform Resource Locator) s in your
unsigned Applet. The Applet will then work on one website only, or locally only.
Instead, use a relative URL
and convert it to an
- Watch out for this one. Sometime when you test your Applets locally
they work, but when you use them on the web they fail with AccessControlException. Remember, Applets are not supposed
to read files, though you can do an AppletContext. showDocument. You
can however read resources in the jar file.
|Applet not inited
||Applet not inited|
- You are using Internet Explorer
which has a defective or missing Java.
- Missing package statement.
- These erroneous Applets will often work with the Java Plug-in, or when
run locally, but will fail with native Javas when run on the web.
- There can also be problems with your jar file having too much or too
little qualification of class names. Your <APPLET
CODE= must have nothing but the class name, without the .class.
- Make sure the case and name exactly match the name of the *.java file, *.class file and class
name. For a class in a package this would have dots in it, e.g.
com.mindprod.mypackage.Myclass, but it would not
have any directory qualification.
- Your CODEBASE= parameters must have an
absolute http://-style reference to the base
directory where the code is stored.
- For a local hard disk, the only thing I could get to work reliably on
NT with all browsers and AppletViewers is leaving the CODEBASE out entirely. You may find for your platform you
have to code it something like this: ///C|//MyDir/ or C:\MyDir\
- Your ARCHIVE= parameter must have a list of
the jar files, separated by commas. If you have too little or too much
qualification, or if you fail to use the file naming conventions of your
server, you will be in trouble.
- You tried to do something in an unsigned Applet only signed Applets are
allowed to do such as reading restricted system properties, perhaps
indirectly via Color. getColor.
|Application Failed To Start
||The application has failed to start because its side-by-side configuration is incorrect.|
|Most likely you are using the Microsoft Express C++ compiler to create your JNI (Java Native Interface).
It links to a run time library which is not present. You need to put the
necessary redistribution support DLLs (Dynamic Link Libraries)
on the path, or install the entire C++ run
time library on all client machines. The catch is other vendors may do the
same thing and you can have versioning problems, more commonly known as
DLL (Dynamic Link Library)
hell. Some compilers allow /MT or /LD static linking to create a standalone
that does not require a run time, but Express 2008 will not.|
||ArithmeticException: / by
|You divided by 0. If it occurred in a paint method, likely this occurred as a result of creating a
Font with zero height.|
|You have used an array index outside the allowable range. There may be
several array references x[i] in the same line.
Don’t leap to conclusions about which one caused the trouble. Arrays
are indexed from 0 to x.length-1, not 1 to x.length the way FØRTRAN programmers are used to. When
you allocate the array you specify the length something like this:
int x = new int[ 10 ];
|The rules of casting arrays and casting the elements of arrays are subtle.
See the gotchas.|
||Bad installation. No jre found in the configuration
|If you got that error message while trying to launch a
JWS (Java Web Start)
application, it means your deployment files are corrupt. This is easy to fix.
At the command line, type javaws.exe -viewer. Then
delete all the applications. Then launch your apps again.|
|bad magic number
||Bad magic number|
- The first four bytes of a class file are supposed to say CAFEBABE in hex. They don’t.
- Most likely the problem is you uploaded your class file to your Web
server using FTP (File Transfer Protocol)
ASCII (American Standard Code for Information Interchange)
mode instead of BINARY mode which mangled the class file.
Oracle bug number 4151665
: Sometimes when a class is not found it gets reported as corrupt instead.
- Novices get this error when they try to run a program without compiling
it first e.g
- If the class file seems ok, consider the possibility some other class
file on the classpath is the one the ClassLoader is looking at.
- See ClassFormatError
||Bad major version number|
|Most likely your class files use a more recent version of Java than the Java
runtime you are using. This most commonly happens with Applets in Internet Explorer which supports only an ancient
version of Java.|
||Applet works fine run as application, but shows a blank
screen without any error message when run as an Applet. There is not even an
Applet loading message.|
|Check the <applet code=com.mindprod.mypackage.Myclass.class tag. It is spelled
code not class.|
|BoxLayout can’t be shared.
||BoxLayout can’t be shared.|
|You wrote something like:|
setLayout ( new
BoxLayout. PAGE_AXIS )
JFrame.contentPane.setLayout ( new BoxLayout( contentPane, BoxLayout. PAGE_AXIS ) );
||Caused by: java.lang.RuntimeException: Broken Pipe!|
|Your pipe connection stopped working. You may have run out of scratch disk
space. You may have clogged RAM (Random Access Memory)
by failing to release resources. Your compressed datastream may be corrupt.
The process reading a pipe may have closed it, so you can’t write more
data to it.|
|can’t create virtual machine
||Could not create the Java virtual machine|
|You wrote java -xxxx.jar instead of
java -jar xxxx.jar|
|Typically you are reading a UTF-8
stream and encounter an illegal binary pattern that has no meaning.|
|class has wrong version
||class file has wrong version 49.0, should be 48.0|
|You trying to run class files compiled with JDK (Java Development Kit)
version 1.5 on an older
JRE (Java Runtime Environment)
|class file contains wrong class
||class file contains wrong class. Please remove or make sure
it appears in the correct subdirectory of the classpath.|
|If the name of your class is HelloWorld then the name of the
source file must be HelloWorld.java and case
matters. You also get this error if you have the wrong or missing package
statement. You could also have the source file in the wrong directory if you
have a complex package structure. If your package is called com.mindprod.com.mindprod.mypackage and your class MyClass, then you had better be in the root directory and the
class file for MyClass hand better be called
MyClass.class and better live in com/mindprod/mypackage, with matching case!|
- You have cast a Class object to a
Class that is not the same class or a super
class of the Class object. This exception
happens when you cast a generic reference to an Object to an invalid class. You must cast it to the class of
the Object or one of its superclasses. You can
find out what class the Object actually is with
- You can cast null into anything without raising a ClassCastException. Generally, this is a Good
Thing™. Otherwise every cast would need an if to specially handle the null case. You might be tempted to
count on ClassCastExceptions to filter out
nulls for you. The following code will not raise a
Cat c = null;
Object o = c;
Dalmatian d = (Dalmatian)o;
In other words, there is one universal representation for null, not a special one for each class. For more detail
- If the error message complains you have tried to cast class
X to class X, it is
complaining that the two different class Xes
belong to different class loaders. Even though they have the same name,
they are treated like logically separate classes.
- If the ClassCastException occurs during a
sort, chances are you forgot the implements
Comparable. See the gotchas for details.
- If you write a factory method like this:
protected CameraButton cameraButtonFactory ( int buttonNumber )
return new LabelledCameraButton ( buttonNumber, this );
and it seems to be producing the wrong kind of objects — ones
from the base class’s version of the method, check the precise
spelling and signature of the method. It had better exactly match the one
in the base class. If it does not exactly match, it will not override. To
guard against this error Bali proposes an explicit overrides keyword.
- You mangled the class file FTP
upload by doing it as ASCII
instead of binary.
- Further, your web server must be configured to send *.class files as
binary rather than ASCII.
It needs a MIME (Multipurpose Internet Mail Extensions)
configuration entry to define *.class files. See MIME for details.
- Sometimes it is actually a CLASSPATH problem. It can’t find the class.
- ClassFormatError: class already loaded. You have a class file twice on
the classpath. It has nothing to do with the DLL
already being loaded. Thankfully, having a DLL
still loaded from the last time you ran is not considered an error.
- ClassFormatError: bad major version. Your ancient 1.1 Java runtime does
not know what to do with a program compiled under
|Thrown when an application tries to load a class through its string name
ClassLoader. findSystemClass or ClassLoader.
loadClass. It is similar to NoClassDefFoundError.
- this occurs only at run time. Usually it means a class that was present
during compilation has disappeared, or the classpath has changed so it is
no longer accessible. It could also happen if you dynamically load a class
and the class is not on the classpath.
- Are you spelling the fully qualified class name correctly on your
Applet tag. Case matters. Double check the case of every letter.
- The class itself references another class that can’t be found.
Are you using APIs (Application Programming Interfaces)
from versions of Java that aren’t supported by your browser?
- Try specifying CODEBASE=. as an Applet parameter, to ensure that the browser is
looking in the right place.
- Are there packages involved? If so, the Applet class needs to be in a
package-appropriate subdirectory, or better still in a jar, not in the same
directory as the HTML (Hypertext Markup Language)
file. If not, you ought to look into putting every class in a some
package before you deploy code; the default (nameless) package is
intended only for test code that won’t be distributed.
- Look at your jar with WinZip. Are all the classes and package names
correct with the correct case? Make sure all the case information is
perfect on your jar-building line.
- Class.forName(String) is short hand
( String, initaliseTrue, currentClassLoader). If the class you are looking for was
loaded by a different ClassLoader you
won’t find the class.
- If you are deploying with FStart, make sure you have included all the
jars used in your JNLP (Java Network Launching Protocol). You may have forgotten some that were on
the classpath or in the ext directory that the app needs. Make sure you
spelled all the jar names correctly and they actually exist on the download
site in the directory you expected.
- In the Java control panel ⇒ advanced ⇒
Java plug-in, trying unticking the option enable the next generation
- If you have been playing games with class loaders, the problem can be
that you are using the wrong classloader to load some particular class. You
might have meant: ClassLoader. getSystemClassLoader, or
(). getContextClassLoader() or some other. Keep
in mind that the same class loaded in different classloaders are
effectively different classes.
- See bad magic number
|You were using JAX to access AWS (Amazon Web Services)
or something similar. A request failed. You can catch the more general
|You tried to delete or add to a Collection
while you were in the middle of running an Iterator over it. To get around this, you must remove elements
via the Iterator object using Iterator.remove rather than
the usual Collection. remove. You can add elements if you use ListIterator.add. See
|You were probing a server on the net. A request timed out. You
can catch the more general java.net.SocketException or java.io.IOException instead.|
|Could not find main-class
||Could not find main-class
|Check that you have the correct package name and class name in
the Java source, in the *.mft file and the
*.jnlp file line <application-desc main-class=com.mindprod.setclock.SetClock />|
|Could not reserve enough space for object heap.
||Error occurred during initialization of VM. Could not
reserve enough space for object heap. Could not create the Java virtual
|You asked for too much RAM
on java.exe -Xmx
|does not contain expected
||myClass.class does not contain myClass as expected, but
MyClass. Please remove the file. Class myClass not found in new.|
- missing caps on new MyClass() reference.
- missing caps on MyClass() obj declaration.
|EOFException in ZIP
end of ZLIB input stream|
|Try using ZipFile instead of ZipInputStream to read a zip created by ZipOutputStream. See Zip
|Exception in thread
||Exception in thread main java.lang.IllegalArgumentException: Comparison method violates its general contract!|
|You have written a Comparator that violates transitivity.
If A > B and B > C then it must be that A > C|
|Thrown when code that is dependent on a keyboard, display, or
mouse is called in an environment that does not support a keyboard, display, or
mouse. Check the java.awt.headless=true Java System property. If you are using X11, check that
the DISPLAY environment variable points to the X11
- In Netscape, inner classes can’t seem to access private variables
of the enclosing class. You don’t discover this until run time.
- Failing to use both the <APPLET ARCHIVE= parameter to specify a
comma-delimited list of jar file names and the CODEBASE= parameter in the
form of an absolute http://-style reference to
where the jar file is.
- Generally problems with CLASSPATH, CODEBASE and ARCHIVE.
- Classes in jar have the wrong amount of qualification stored with
- Classes in packages are not stored in the correspondingly named
directories. See CLASSPATH and java.exe in the
Java glossary for a fuller discussion.
- Using an old library with new code. In the old library a method might
be private where in the new it might be public.
: Input length must be multiple of 8 when decrypting
with padded cipher.|
|Literally, the problem is the message to be decrypted is not a multiple of
8 bytes, when the encryption padding algorithm
should have made it a multiple of 8 bytes. Possible
- The message was truncated or garbled in the process of storing,
armouring or transmitting it.
Dump it out in hex immediately after
encrypting and immediately before decrypting to make sure it is identical.
- You specified different encryption and decryption algorithm
- For good measure, make sure both the encryption and decryption were
done with the same version of the JCE (Java Cryptography Extension).
thrown when an object’s wait(), notify(), or notifyAll() method is
called from a thread that does not own the object’s monitor. In other
words, the Thread using these methods must be
executing inside a synchronised block locking on the object whose wait etc. method you are calling.|
||Illegal use of nonvirtual function call|
|An inner class is not permitted to call private methods of the enclosing
outer class. It is permitted to call protected methods. This error message
appears in the old Symantec 2.5a
Java only when you have debugging turned off. Normally the compiler should
catch this error, but if it doesn’t it will show up at run time with
this strange error message.|
|Image won’t paint
||Your app uses drawImage,
paintComponent or simply Container.add. Yet nothing appears.|
|See the list of possible
||When generating Javadoc, you get Identifier Expected|
|You are using old version of javadoc.exe that does not understand the newer Java syntax, or
perhaps you are trying to generate Javadoc before you have a clean
||Incompatible types, found : java.lang.Object, required:
java.io.File: for ( File file : wantedFiles )|
|Make sure you declare your File
collection class with implements Iterable< File> and its
iterator method with public Iterator<
- You forgot the static on your main method.
- Any illegal use of a legal class.
- You have made a change to a class and are still referencing it from an
another class by its old signatures. Try deleting all class files and
||OutOfMemoryError: string intern
|You have too many interned
strings. Some older JVM (Java Virtual Machine)
’s may limit you to 64K Strings, which leaves
perhaps 50,000 for your application.|
local class incompatible: stream classdesc serialVersionUID =
- You serialised some objects, then modified the class source code a tad,
say by adding another convenience constructor. Java panicked and decided
the old objects were no longer compatible when you tried to read them back
in. You can soothe it by manually assigning your objects class version
- It is up to you to change that number any time the class changes in a
way that would affect the old object’s ability to be read back with
the new class definition. Java has some flexibility for the old and new
objects not to have a perfect match. serialVersionUID is a magic variable name. Spell it exactly
like that. If you have used a serialVersionUID,
perhaps you have actually changed the layout of the class fields without a
new serialVersionUID. Finally, perhaps you failed
to provide a no-arg constructor.
- You serialised some objects, then changed the format of the objects,
rightly changed the serialVersionUID, then tried
to read the old object back with the new class definition.
Oracle’s JDK Platform Guide to InvalidClassException
|This is a wrapper exception. You will get one if a method or
constructor you invoke with reflection throws an exception. Because the
compiler cannot analyse methods called through reflection, the reflection
runtime wraps any errors thrown in the called routines in a predictable
exception called the InvocationTargetException which
you can catch. Use InvocationTargetException.
getCause and InvocationTargetException. getTargetException to find more details. One way to trigger one
is to initialise variables in an Applet rather than
setting their initial values in the init
||IOException: invalid header
|Jar Not Signed With Same Certificate
||Your JAR-resources in JNLP-File are not signed from the same
|You will have to resign all jars mentioned in the
file with the same certificate.|
||You have an obsolete JavaMail or Java Activation Framework
|Make sure you don’t have more that one mail.jar or jmf.jar on the
||The application has requested a version of the
(version 1.5+) that currently is not locally
|If the JRE is not installed, install
it. Normally, you only need the latest version,1.8.0_74,
none of the older ones. This is a common Java Web Start problem. The
is indeed installed and works fine for non Java Web Start apps. Java Web
Start apps sometimes work fine launched from a browser, but fail when
launched from a desktop shortcut. My theory is somehow the registry or the
Java Web Start development cache gets corrupted in a way that causes Java to
use a version of javaws.exe with the wrong matching
directory. There will be at least three copies on your machine C:\Program Files\java\jre1.8.0_74\
\bin\javaws.exe, J:\Program Files\java\jdk1.8.0_74\
\bin\javaws.exe and C:\Windows\System32\javaws.exe.
Kludges around the bug include:
Here is how to fix the problem permanently. Unfortunately, this is a
difficult, time-consuming procedure and does not always work:
- Always launch Java Web Start apps inside a browser.
- Create your own desktop shortcuts with an explicit link to a local copy
of the *.jnlp file and possibly C:\Program Files\java\jre1.8.0_74\
\bin\javaws.exe if you are unsure associations are set to use that
version of javaws.exe.
- Explicitly launch the JRE
javaws.exe with C:\Program Files\java\jre1.8.0_74\
\bin\javaws.exe -viewer and use it to
launch your apps or create your shortcuts.
- Uninstall any JREs and
JDKs including the
SQL (Standard Query Language)
- Manually strip out any remaining JRE/JDK files, including those in
C:\Windows\System32 and C:\Users\
- Manually delete any references to the JRE/JDK from the registry.
- Remove any Java Web Start desktop shortcuts or menu items.
- run a registry
- run NTRegOpt.
- Reinstall the JDK
with associated JRE, making sure you select a drive explicitly
for each of the three pieces, the JDK,
the database and the JRE.
- Fix up the set environment and the ext directories.
|load: class not found
||load: class X not found|
|Likely you are using Microsoft’s ancient old JVM
in Internet Explorer that supports only up to Java 1.1.4. Check which version
of Java you are using with Wassup. Make sure you are using the most recent
JRE in C:\Program Files\java\jre1.8.0_74\
|method not found
||method X not found|
|This is caused by using obsolete jar files. The version of the
class in the jar is missing the method, but at compile time, the java file had
the method. The way to avoid this is to do a clean compile periodically
deleting all class and jar files and rebuilding them.|
||MissingResourceException: Can’t find bundle base name
|The resources you need are missing from the main jar or the jar
they live in is not on the classpath. Keep in mind that jars have an internal
manifest classpath and Java Web Start using the JNLP
file to locate the jars.|
Detail from The Scream, by Edvard Munch
This one is a bitch to track down. It has so many causes. Java is so picky! A
misplaced comma, quote, semicolon, extraneous extension or even the wrong
upper/lower case can derail the whole program. I hope some will implement the
NoClassDefFoundError Amanuensis to
make the problem easier to track down.
Sun explains that it is thrown when Java Virtual Machine or a ClassLoader
instance tries to load in the definition of a class (as part of a normal
method call or as part of creating a new instance using the new expression)
and no definition of the class could be found. The searched-for class
definition existed when the currently executing class was compiled, but the
definition can no longer be found. It is similar to a ClassNotFoundException. This gives you the hint that a
NoClassDefFoundError problem was
not with caused by a
- Essentially the problem is the place and name where you put the class
file, free-standing on disk or inside a jar, does match the place and name
it should have, based on the classpath, the package name and the class
name. Everything is case-sensitive and sensitive to the tiniest typo.
Unfortunately, there is currently no tool to tell you where the class
should be placed (usually there are several possibilities) or where it is
- You got the class name wrong on the java.exe
command line. It must include the full package name and class separated by
dots, without the *.class e.g.
java.exe com.mindprod.converter.Convertnot just the class:
java.exe ConvertNewbies often get in trouble by adding a *.java or *.class suffix. In
contrast, javac.exe demands the *.java extension.
- You get an error message like this: Exception in
thread main java.lang.NoClassDefFoundError:
XXX/java. When attempting to compile, you keyed java.exe XXX.java instead of javac.exe
- Java can’t find the class mentioned. It is missing from the jar
or classpath. Java may need it because it occurs as a class or superclass
in a serialised ObjectStream or because you
called a method of that class. You don’t find out about the problem
at compile time or even load time. You only find out when you actually go
to use that missing class. The missing class was present when the class
referencing it was compiled (perhaps on somebody else’s machine) but
the missing class is no longer accessible. To fix a vanilla NoClassDefFoundError, search the all the jar files on your
machine for the missing class. Funduc Search and Replace will do that. If you can’t find it,
scour the web for a download. When you find it, make sure its jar is on
the general classpath, the project classpath, the command line classpath
or in the ext directories of the various
JREs (Java Runtime Environments)
you have installed. There will be at least two ext directories.
- Three diagnostic tools you may find helpful:
- To dump the classpath that you are actually using at some point in
your code insert: You must first determine if the classpath is correct
- If you have a jar or more than one class, assign each class to a
package! Package-less classes are for one-shot, single-class throw-away
- Then when you are sure the jar or directory you want is truly on
the classpath (it is not sufficient for the directory that the jar is
in be on the classpath), then check the contents of the jar with
jarlook to make sure your package/class is in
there, spelled precisely, including case. You can download jarlook with source.
jarcheck as well. It will help you detect problems with
unexpected target versions of class files in your jars.
- Recall that reconstitution of serialized files uses Class. forName to instantiate
all the classes buried in the files. Genjar or equivalent does not know to include these classes in your
jar. It is up to you to include all the classes you need manually. You
will keep getting the dreaded NoClassDefFoundError until you have nailed them all.
- Look for a typo in spelling the class file name in the file or in the
command line invoking its main method. Copy/paste to make sure they are
absolutely identical including case.
- Check your classpath. Make
sure you used semicolons or colons as appropriate. Don’t specify null
fields in your classpath, e.g. two semicolons in a row.
- The problem is essentially either the class is not on the classpath or
the classpath is wrong. You must first determine if the classpath is
- If your program used to work and it suddenly stopped working, did you upgrade your JDK/JRE? If
so, you likely forgot to copy over the jars to the C:\Program Files\java\jre1.8.0_74\
\lib\ext and C:\Program Files\java\jre1.8.0_74\
- You wrote some code like this:
private static final int a;
a = someMethod();
}If the class you are loading throws an
Exception during the static initialisation, it will show up as a ExceptionInInitializerError rather
than the original Exception, which your code
may not be prepared to handle. When your code later goes to use the
class, you will get a NoClassDefFoundException.
- If you see the phrase wrong name in the
error message, it means you are not consistently naming the packagename. ClassName
everywhere. Perhaps you left off the packagename, or got the case wrong, or
made a typo in either the package or class name.
- If you have two packages that use classes from each other, each jar
must have all the classes of the other package that it uses, or that it
uses indirectly uses.
- You must put the -classpath option before the
class name on the java command line. To remember the order, you can think
of it like this. Java.exe needs to know the
classpath before it can search for the class.
- You got package name wrong at the top of the source file, or left it
out entirely. It does not match the one when you built the jar. It is
- If this is an Applet, you got the
<applet code=com.mindprod.mypackage.MyClass.class wrong. Perhaps you
forgot the package part of the name or you forgot the .class. The package names in the jar may not be right. The
<applet archive=myjar.jar may not match a jar file containing the needed
- If you use java.exe -jar, it ignores your
classpath environment variable and any -classpath
option without comment! All your classes must be in the jar.
java.exe -cp C:\javamail-1.3.3_01\mail.jar -jar bulk.jarwon’t be able to find any of the classes in
mail.jar. You must copy mail.jar to the
ext directory or mention the mail.jar in
the manifest Class-Path: entry.
- Did you remember to include. on your classpath?
- If you got the exception trying to execute a class in a jar, check with
WinZip that the pathnames inside the jar on that class exactly match the
package structure, including case. If you don’t know what I am
talking about, see jar for details.
Make sure the class you are trying to call has the expected package
statement. Check the manifest to make sure the fully qualified name of the
main-class is properly specified.
- You are trying to use a program compiled under
Java version 1.4 or later
with an old Java 1.1.5 runtime, often the one in Internet Explorer. The
old class library is missing many of the new methods. Any other version
mismatch where you run new code on old runtimes can cause the similar
problems. Check the runtime version
is one of the most likely candidates for a method from 1.5+ not available
under earlier JVMs (Java Virtual Machines).
- Have you got a simple HelloWorld working yet? If not, your problem may be
in the way you installed the JDK or
JRE. If you have trouble, read up on
javac.exe, java.exe and classpath.
- Java is case-sensitive. Have you got the name of the class spelled
exactly the same way everywhere it is used, including the name of the
*.java file, with class names always starting with
a capital letter and package names pure lower case?
- One of your static initialisers invokes a
function that uses a static field not yet
- Did you remember to make your kickoff class, the one you mentioned in
the java command line, public?
- Does your main method have signature exactly like this?
public static void main( String args )
- Somehow your runtime is having trouble finding classes it could find at
compile time. Check your CLASSPATH. Make sure all the classes are available.
- Check your java.exe command
line. Your current directory is crucial. You must specify fully qualified
class names, without the .class extension.
- Consider combining class files into a single jar file. Jars cause far less trouble than individual class
files, especially when you export them to a server or someone else’s
- Check that your browser supports jar files. Fortunately, all the modern
ones mentioned under browsers do.
- You can get this error if you try to run an Applet on an old browser since it will not have the needed
- Watch \ and /.
In string literals \ appears as \\.
- Make sure when developing classes for an extension i.e. class or jar
files that live in the lib/ext/ folder, make sure
you do not have duplicate classes. Classes from extension folders will
always be loaded before any other classpath, therefore making it impossible
to test other development versions not in the extensions folder. Make sure
extensions *.jar’s are complete (i.e., not
reliant any additional classes). Make sure the *.jar in the extensions folder is up to date. Basically only
thoroughly-tested, stable code should live in the extensions folder.
- Have you accidentally used a system package name for your own
- If every program gives NoClassDefFoundErrors, try uninstalling all Java tools and
s, clean out the registry and then reinstall. Make sure you have only
the latest Java on your machine.
- If your NoClassDefFoundError occurs only
sporadically, here is a possible cause: You are running some classes in a
jar file which is stored on a network mapped drive in MS Windows. Sun keeps
the jar files open in order to re-load classes which haven’t been
used in a while and occasional network problems will force the jar to
close. The JVM
doesn’t know to re-open the jar when the network mapped drive
reconnects and simply reports that various classes (different each time)
no longer exist. The solution is either make sure the network is reliable,
use a network file system which doesn’t close if drives are
temporarily unavailable, or locate all jar files on local drives.
- If you change the jars used by your JSP (Java Server Pages)
code, make sure you manually delete the generated class files (classes in
the WEB-INF tree for Caucho Resin). The womb
won’t be smart enough to do that on its own and you will get all
manner of NoClassDefFoundErrors.
- If you have classes included in your project that don’t live in
the same directory as the project, in Café you must
also do a Project ⇒ Options
⇒ Directory ⇒ Classes to include their directories in the
invisible CLASSPATH for the project. Simply
including the java or class files in the project is not sufficient. Other
IDEs (Integrated Development Environments)
may have similar gotchas.
- If your code works then suddenly stops working, chances are you have
uninstalled a JRE/JDK or installed a new one and the current JDK/JRE does
not have the full complement of jars in the ext
Sooner or later you will have to reinstall the JDK/JRE and you will lose your ext directories. You can quickly rebuild them if you maintain a bat file like this and run
it after every JRE/JDK install. Adjust the file to account for where your ext dirs are and where the jars are you need.
- Sometimes the problem is with your build. Try using ant and a script based on one of my examples. Ant has
a better chance of getting it right that some ad hoc build script.
- You overrode JPanel.getParent
or perhaps some other crucial piece of Oracle’s code without reproducing
its functionality typically by calling super.xxx().
- Check the integrity of all jars. Some may have been truncated during
upload. Verify with jarsigner.exe or winzip.exe.
- An the app works fine locally but fails when you deploy it on a server
because you failed to upload all the class files needed to the server
(usually in jar form).
|You did a new
() when your program was not running inside a servlet womb which provides the
default Initial context factory. You can provide a factory class by naming it
is a SET environment parameter, or a Java system
property java.naming.factory.initial. Here is some
typical code: |
|You called Iterator.next when there were no more elements. You must either call
isNext first, or use the for ( Thing:
thing : thingCollection
) syntax which handles it all for you automatically.|
|Likely you are mixing an old library with new code or vice
versa. The definitions and references to a class differ in whether they include
some field. If you have source for the libraries, recompile everything to
discover the precise error. If not, check to make sure you are using the most
up-to-date libraries (or ones of the appropriate vintage) and clean compile all
your code making sure the libraries you run with are also on the classpath at
compile time. Compilation may clear up the problem or at least make it more
|Use Transport.sendMessage not
|You forgot to put implements Serializable on the class you are doing a writeObject on. Since writeObject
also writes out all the objects pointed to by that object, by the objects
those objects point to, ad infinitum, all those classes too must be marked
implements Serializable. Any references to non-serializable classes must
be marked transient. While you are at it, give
each of those classes
Oracle’s JDK Platform Guide to NotSerializableException
||NTLDR is missing|
- You are trying to boot from a non-system diskette (or disk) in Windows
- The crucial loader program used in booting has been deleted from your
|If you try to execute a piece of code like this when s is null you will get a NullPointerException.
To learn about exceptions in general and try/catch to recover from them, see
exceptions. Here are some of the
- A reference variable is null, when you used it to access a field or
- Autounboxing can make NullPointerExceptions
hard to track down. Innocent looking code like int result = getResult(); can throw a NullPointerException if autounboxing is hiding what is
really happening, namely int result = getResult().intValue(); It will fail if getResult returns null instead
of an Integer object.
- Examine the stack trace to figure out where in the code it happening
and how you got there. The stack trace shows the exact line the problem was
detected (not necessarily the line at fault though). That gives you a clue
to get started. You can put some code of the form:
if ( p == null )
out.println( "p was null" );
assert p != null : "p was null";
- Narrow it down to the precise variable giving the trouble. Then you
have to sit and think about why that variable is null. The
real problem could be much earlier in the code and the problem propagated
through to the point where it eventually surfaced as an exception. You must
figure out where it was supposed to be set and have a look at that code
and why it is failing. Most of the time you simply forgot to initialise.
The easiest way to track the causes down is using a source-level
debugger such as Intellij Idea or Eclipse You can trace the flow of execution, or
examine the state of the universe at the time of failure.
- If you don’t want to use a debugger, pepper your code with
assertions to track down just what is
ensureNotNull( thing, "thing" );
assert thing != null : "thing is null";
- Your ensureNotNull( Object toTest ) method might print
an error message if toTest is null, then throw a
new NullPointerException. By making ensureNotNull final and using
an if (DEBUG) inside ensureNotNull, the inline expansions will have no overhead
in production and you can leave the debugging assertions in place to be
reactivated later if ever needed.
- Most commonly you forgot statements of the form: myArray = new int; or myThing = new
Thing(); See the array initialisation gotchas. These are
the most common of runtime errors.
- You may not call getParameter in the
Applet constructor. Move that code to
- Sometimes the problem is redeclaring a local variable with the same
name as an instance variable. You might have initialised one but not the
other. Beware having two variables with the same name, one local and one
instance, It is very easy to do inadvertently and Javac will not warn you, though Jikes will e.g.
ArrayList thelist = new ArrayList( 149 );instead
thelist = new ArrayList( 149 );You work with the local variable thinking you are
working with the instance variable and poof, your values are lost as soon as the local
goes out of scope, leaving the instance version null. This is the way I most commonly
create NullPointerExceptions for myself, when I convert a local
variable to an instance one when I have to break a method up that uses the variable and
forget to take out the local declaration.
- Be very careful calling any methods inside your constructors. If
subclasses override them, you will be invoking the subclass’s
version, which may be attempting to use fields that have not been
initialised yet. You won’t get a warning message! The problem usually
shows up as puzzling NullPointerExceptions. The
way out is to move code out of the constructor, often to the addNotify method. However,
addNotify can get in analogous problem to the
constructor since it too is overridden and it may use overridden
- If the problem is in Oracle’s code that you call or indirectly call,
(i.e. no source code line number) look at the place in your code where you
trigger the chain of calls. Insert some debug code there to examine the
parameters and the fields in any objects you pass. If you can’t track
it from that, use a source code debugger like Eclipse that lets you follow
program flow inside Oracle’s code. For example, your code creates an
event, asking it to operate on some null component and the problem does
not show up until later when the event is dispatched and handled by
- The Nice language manages to
detect NullPointerExceptions at compile time
instead of run time the way Java does.
|In converting a String to internal
int/ long etc. with
parseInt or brethren, the number was not a valid
string of digits. The usual problem is leading or trailing spaces on your
number. The sign must come ahead of the number, no commas. Localisation may
have an effect on what constitutes a valid number. Sometimes it can be the
number is too big to fit in the int, long etc.|
|Attempting to use readObject on a
stream that does not contain objects, or attempting to read past the end of
|You have run out of memory. You have filled up virtual
with objects and the garbage collector can’t free any more
RAM. You can expand the effective size of virtual
ram by putting options on the java.exe command line.
See the-Xss64k -Xoss300k -Xms4m and -Xmx10m options described under java.exe. Perhaps you have read some ridiculously large
number from a DataInputStream to use as the size
of an array. Perhaps you have used a method recursively without terminating
at reasonable depth and filled memory that way.
|IBM (International Business Machines)
Visual Age sometimes makes a noise like an elevator arriving every time you
click anything. No error message is visible anywhere. It means you are
debugging a multi-thread program and a higher priority thread is blocking the
one you want to debug.|
||No error while developing. Security
Violation in production.|
|Applets can only access the server they were loaded from.|
|signal 10 error
||Unexpected Signal : 10|
|Signal 10 is a bus error. It’s generally caused by
attempting to perform an unaligned bus operation (for example, reading a long
from an odd address), so it isn’t something that will normally occur in a
pure java application unless there is a bug in the JVM.
If you have native code in your application though, that could be the cause.
On some platforms, an application will get a bus error if its executable file
or one of its shared libraries are replaced while the application is
||StackOverflowError Stack size too
small Use java -Xss to increase default stacksize.|
|These usually happen when you have recursion, a method that calls itself,
perhaps indirectly via a second method. You have simply nested to deeply.
Another source of the problem is calling method x() or this.x() when you meant to call super. x(), usually when inside
method x. If you legitimately overflowed the
stack, you may rescue yourself by getting the runtime to allocate more memory
for the stack for each thread with java.exe -Xss128
|Start Service Failed
||StartService FAILED 1056: Instance of the service is already
|Just ignore this spurious error message. There is nothing the
matter. Window is being prissy and chastising you for asking it to start a
service, when it already did so earlier.|
|The object stream is scrambled. Perhaps you are trying to read human-readable
data, e.g. something that was not prepared with writeObject. Perhaps you have classes missing or the classes
used in the stream are obsolete. Perhaps you tried to use append mode to tack
more onto the end of your stream file after it was closed and later reopened
in append mode. That does
Oracle’s JDK Platform Guide to StreamCorruptedException
||java.lang.StringIndexOutOfBoundsException: String index out of
|The parameters you gave to the substring,
charAt, index or
related String method were outside the range of
the base String, or the start point was after the
end point. See substring
gotchas. To track it down, dump the base String and the indexing parameters with System. out. println.|
|Applets behind a firewall may not have access to DNS (Domain Name Service).
You must encode your CODEBASE as an IP (Internet Protocol)
instead of a DNS
|unable to load for debugging
||Unable to load MyClass.class for debugging.|
- Symantec support suggests copying all the DLLs
in VCP\JAVA\BIN to VCP\BIN to correct stability problems. If you do this, all
debugging will cease to function. Delete any DLL
in VCP\BIN that also exists is VCP\JAVA\BIN.
- Check that you fully qualified the name of your class with its package
name, e.g. com.mindprod.business.TestDate in the
Project section of Visual Cafe, no trailing .class and that the upper and lower case is precisely
correct. Read the section in the glossary on CLASSPATH and under java.exe on how packages, classnames,
the directory structure and the CLASSPATH all interact. If that does not
solve it, I have bad news.
- Windows 95 has the most incredibly inept scheme for dealing with
from different vendors that just happen to have the same 8+3 name, (even
when they are stored in totally different directories). Whichever
application starts first gets its DLLs
installed and every other app that comes afterward has to use them. If you
start some app before VC, it may load incompatible
DLLs. To avoid this, load VC first. Then the
other apps may stop working. Phttt! Mr. Gates has guaranteed himself a seat
in hell for this (and for the confounded registry where all configuration
information for all applications is lumped in one unrestorable basket).
There should be separate system DLLs
and application DLLs
with no possibility of DLLs
provided by one vendor being foisted on some other. Try starting Visual
Cafe before any other app and keep it running. It stands a better chance
then of getting its own DLLs
|Unable to locate tools.jar
||Unable to locate tools.jar. Expected to find it in
|It seems to be looking for tools.jar in the
instead of the JDK. Make sure all the JDK
directories contain the expected files, including tools.jar. I found that uninstalling the
and reinstalling them cleared this up. Especially for beta software you are
safer to uninstall and reinstall rather than install over top.|
|Unable to open file xxx.exe
||Fatal error (0): Unable to open file xxx.exe|
|In JET (Just Enough Time)
when compiling, you forgot to terminate execution of your app before redoing
|unable to run
||Unable to run MyClass.class: Check that you have properly
specified name of the class containing main in your project settings.|
|Your SlickEdit vep project file is not in the same directory
with the *.java and *.class
files that compose the class containing Main.|
||javax.jnlp.UnavailableServiceException: Running a
app without JWS.|
|If you run a Java Web Start apps and try to use the
service library, you will get this exception. You can only use that library in
the context of Java Web Start.|
invalid method hash.|
- the receiver does not have the needed class file.
- the receiver and sender have different versions of the class file.
- your stubs are out of date.
- you screwed up something doing RMI.
Try a very simple case and get that going, then gradually add complexity.
When it stops working you have a much better idea where to look for the
: Cannot recover key|
|You gave the wrong password when you accessed the keystore with
|This means you had some trouble loading a library containing native class
||java.lang.UnsupportedClassVersionError: Unsupported major.minor
SomeClass version (nn.n).|
|You used a method that your JVM
does not support. This most commonly happens when you target for
Java version 1.6
but inadvertently use a Java version 1.7
method. The compiler will not warn you at compile time. I run into it most
commonly when I run jet whose run time is Java version 1.6.
The problem goes away when I use a Java version 1.7
JVM. Look at the since comments in the Javadoc to
make sure you are not using any too new methods. If you use the -bootpath option to provide Java version 1.6
jars, then the compiler can warn you about using a Java version 1.7
method. Try upgrading or reverting your JVM.
This is likely a bug — some native method not prepared to function
under the current version. Try uninstalling all your java, purging the files,
then reinstall your JDKs (Java Development Kits)
s, working from oldest to newest. The problem is caused by some sort of clash
with code from one version interacting with code from another. Watch your
classpath. You could have no classes on it for a more advanced JVM than you are using. Check which version you
are using with:
java.exe -versionor use Wassup
for more detail.
||javax.activation.UnsupportedDataTypeException: no object DCH for
|You have an obsolete JavaMail or
Java Activation Framework jar.|
||Exception in thread xxx java.lang.VerifyError: Accessing
value from universalised register 2.|
|This is a compiler bug. It comes from redefining a local variable. Just use two
different names. Could come from other compiler bugs. Try using a the current
compiler. It can also come from using Outer.this
from a non-inner class. In JDK
1.4.2+, the compiler should detect the problem
rather than runtime.|
||This is a NoClassDefFoundError where you got package name
wrong at the top of the source file. It does not match the one when you built
the jar. It is case-sensitive.|
||class file has wrong version 48.0, should be 47.0|
|You have partly a Java version 1.4
and partly an earlier version of Java installed. Check out each copy of
java.exe and with the -version option. If necessary uninstall all
s, prune the registry of
references to Java, prune the hard disk of java directories and reinstall
from scratch. Watch out for any JDKs
that came embedded with an IDE (Integrated Development Environment).
Watch out specially for the C:\WINNT\system32\java.exe. It too should be 1.4. You may have
the rt.jar file from a different version.|
system cannot find the file specified.|
|Usually the zip file in question is the distribution jar containing your
class files and resources. For some reason it can’t be found. You may
have misspelled it or used the wrong syntax to specify it.