1. Explore
  2. »
  3. Java Runtime

Java Runtime errors

Core environment and runtime library

https://java.com
Solution coverage:
Summary coverage:

Top patterns

  1. The class could not be found

    This error pattern looks similar to error pattern 88439.

    However, in this case, we are sure that this happens when sun.misc.URLClassPath.getResource(String name, boolean check) returns null. Practically every exception that happens in getResource is handled by returning null.

  2. A class is not available on the classpath or the class loader is closed

    java.lang.ClassNotFoundException is one of the most frequent exceptions in Java. It is a runtime error, however, it does not signal a bug in your application logic, but rather an issue with the environment (build system, dependency management, runtime environment, etc.)

    According to the javadoc, it "is thrown when an application tries to load in a class through its string name". There are several different situations leading to this error and you have to examine the stack trace thoroughly to be able to decide how to solve this problem.

    The first thing to check is whether you get this checked exception directly, or wrapped in a java.class.NoClassDefFoundException. The latter happens when the class not found was resolved during compilation time, but not found during runtime, which is a bit different than the first case and it needs special care. If this is what happened to you, then you should read that article (coming soon).

    Next we ask what is the class that was not found. Fortunately, in most cases, you can see it in the message of the exception. If this class was specified by you (either directly in the code, or via a configuration file), double check that you did not misspell it. Some practical advices:

    • Make sure you use the fully qualified name of the class (e.g. org.postgresql.ds.PGSimpleDataSource)
    • When loading a nested class, make sure you use the proper name (joined with a $ sign, e.g. test.MyClass$InnerClass).
    • If you are unsure, you can check the name of the class in the code by using MyClass.class.getName()

    If none of the above helped then you have an issue with your classpath, which requires some time and experience to resolve. When the java.lang.ClassNotFoundException is related to a third party library, you might want to ask for help in their support forums. However, if you want to debug it yourself, let me equip you with some theoretical and practical knowledge.

    • To understand what is class loading in Java, start with this StackOverflow question or the Java Language Specification §12.2. Roughly speaking, the classes that your application use are located in jar files on the file system. The classpath is a list of jar files which are searched through when your application loads a class. The java.lang.ClassNotFoundException means that the class you wanted to load is not present in any of the jar files on the classpath.
    • The configuration of your classpath depends on your runtime environment (i.e. do you run the application from console, from IDE, web container, etc), you can find more information on the specific forums. However, if you can use breakpoints to stop at specific points in your application, stop at the first line of java.net.URLClassLoader.findClass and check the value of the field ucp.
    • You should have an idea on which jar file contains the class that could not be loaded, and look for that jar in the classpath. If it is not there, you have to add that jar to the classpath (precise details depend on the runtime environment).
    • If you find the jar you suspect to contain your class, check if it is true by opening the jar file (they are simple zip files actually) and look for the class definition in the directory structure in it (the directory structure must be identical to the package structure of the java code). At this point you should realize that the class is not present, otherwise the problem would have been found previously during debugging.
    • There are two reasons for class not being present in the jar: the first is that you have an incorrect version of the library you wanted to use. To fix this, you have to tweak your build system (maven, ant, sbt, gradle etc) by making sure that you configured the right version of the library as the dependency, and that you don’t have conflicting library versions. To find out how to do this, look for help on the forums of that build system.
    • The other reason of the class not being present is that it’s a bug in that library. If this is a third-party library, you might want to check the support forum and the release notes. If this library was written by you, then try to rebuild this library and check if the class you look for is present in the resulting jar file.
  3. Client cannot establish connection with the server

    Roughly there are three categories of this problem:

    • no network available: Probably your machine's network interface is down. Check if you have internet and your application has permissions to use the network interface
    • connection refused: The address you are trying to connect is not listening. Check if you did not misspelled the host or the port. Also verify that the server you are trying to reach is actually running and listening.
    • connection timed out: The server took too much time to respond. You either have to increase the timeout limit or speed up the server.
Error patternsPackagesClassesMethodsExceptions
DescriptionException TypeEntry MethodWeb pages

The class could not be found

java.lang.ClassNotFoundException
java.net.URLClassLoader.findClass
6932Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6932

A class is not available on the classpath or the class loader is closed

java.lang.ClassNotFoundException
2 frames hidden
java.net.URLClassLoader.findClass
6524Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6524

Client cannot establish connection with the server

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4814Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4814

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
2 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4633Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4633

ClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
3 frames hidden
java.lang.ClassLoader.loadClass
4592Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4592

Unable to convert String to numbers as the provided String is not comprised of real numbers

java.lang.NumberFormatException
java.lang.NumberFormatException.forInputString
4348Web pages
1Solution
NumberFormatExceptionNumberFormatException.forInputString4348

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
4 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4313Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4313

Failed to load the class from current classpath

java.lang.ClassNotFoundException
5 frames hidden
java.lang.ClassLoader.loadClass
4263Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4263

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
5 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4089Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4089

Failed to load the class from current classpath

java.lang.ClassNotFoundException
6 frames hidden
java.lang.ClassLoader.loadClass
4075Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4075

SecurityManager permission too restrictive or unable to find policy file

java.security.AccessControlException
java.security.AccessControlContext.checkPermission
3648Web pages
1Solution
AccessControlExceptionAccessControlContext.checkPermission3648

Unable to open file, file not found in the path provided

java.io.FileNotFoundException
java.io.FileInputStream.open
3554Web pages
1Solution
FileNotFoundExceptionFileInputStream.open3554

AccessController.checkPermission() has thrown an AccessControlException

java.security.AccessControlException
1 frames hidden
java.security.AccessController.checkPermission
3495Web pages
AccessControlExceptionAccessController.checkPermission3495

SecurityManager.checkPermission() has thrown an AccessControlException

java.security.AccessControlException
2 frames hidden
java.lang.SecurityManager.checkPermission
3250Web pages
AccessControlExceptionSecurityManager.checkPermission3250

FileInputStream.<init>() has thrown a FileNotFoundException

java.io.FileNotFoundException
1 frames hidden
java.io.FileInputStream.<init>
3169Web pages
FileNotFoundExceptionFileInputStream.<init>3169

Class version incompatible with current JRE version

java.lang.UnsupportedClassVersionError
java.lang.ClassLoader.defineClass1
3075Web pages
UnsupportedClassVersionErrorClassLoader.defineClass13075

PlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
1 frames hidden
java.net.PlainSocketImpl.doConnect
2794Web pages
ConnectExceptionPlainSocketImpl.doConnect2794

PlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.PlainSocketImpl.connectToAddress
2751Web pages
ConnectExceptionPlainSocketImpl.connectToAddress2751

PlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.PlainSocketImpl.connect
2734Web pages
ConnectExceptionPlainSocketImpl.connect2734

Start or end index provided to substring method outside the range of String indices

java.lang.StringIndexOutOfBoundsException
java.lang.String.substring
2386Web pages
1Solution
StringIndexOutOfBoundsExceptionString.substring2386

Unable to find library file in java library path

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader.loadLibrary
2332Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary2332

Incompatible dependency version or class not found in classpath

java.lang.NoClassDefFoundError
java.lang.ClassLoader.defineClass1
2309Web pages
1Solution
NoClassDefFoundErrorClassLoader.defineClass12309

JNI unable to load native library

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader$NativeLibrary.load
2260Web pages
1Solution
UnsatisfiedLinkErrorClassLoader$NativeLibrary.load2260

Runtime.loadLibrary0() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
1 frames hidden
java.lang.Runtime.loadLibrary0
2101Web pages
UnsatisfiedLinkErrorRuntime.loadLibrary02101

System.loadLibrary() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
2 frames hidden
java.lang.System.loadLibrary
2086Web pages
UnsatisfiedLinkErrorSystem.loadLibrary2086

Unable to read from socket, server disconnected abruptly

java.net.SocketException
java.net.SocketInputStream.read
2029Web pages
SocketExceptionSocketInputStream.read2029

ClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
1 frames hidden
java.lang.ClassLoader.defineClass
1967Web pages
1Solution
UnsupportedClassVersionErrorClassLoader.defineClass1967

Unable to locate class in the dependent libraries or classpath

java.lang.ClassNotFoundException
2 frames hidden
java.lang.ClassLoader.loadClass
1961Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass1961

AbstractPlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
1 frames hidden
java.net.AbstractPlainSocketImpl.doConnect
1925Web pages
ConnectExceptionAbstractPlainSocketImpl.doConnect1925

AbstractPlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.AbstractPlainSocketImpl.connectToAddress
1909Web pages
ConnectExceptionAbstractPlainSocketImpl.connectToAddress1909

AbstractPlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.AbstractPlainSocketImpl.connect
1902Web pages
ConnectExceptionAbstractPlainSocketImpl.connect1902

ClassLoader.loadLibrary0() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
1 frames hidden
java.lang.ClassLoader.loadLibrary0
1880Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary01880

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.SocksSocketImpl.connect
1875Web pages
ConnectExceptionSocksSocketImpl.connect1875

ClassLoader.loadLibrary() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
2 frames hidden
java.lang.ClassLoader.loadLibrary
1864Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary1864

Client unable to complete writing request, network issue or server disconnected abruptly

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1863Web pages
SocketExceptionSocketOutputStream.socketWrite01863

Java Runtime cannot connect a network socket

java.net.ConnectException
5 frames hidden
java.net.Socket.connect
1856Web pages
1Solution
ConnectExceptionSocket.connect1856

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.SocksSocketImpl.connect
1837Web pages
ConnectExceptionSocksSocketImpl.connect1837

Socket.connect() has thrown a ConnectException

java.net.ConnectException
5 frames hidden
java.net.Socket.connect
1823Web pages
ConnectExceptionSocket.connect1823

SocketOutputStream.socketWrite() has thrown a SocketException

java.net.SocketException
1 frames hidden
java.net.SocketOutputStream.socketWrite
1818Web pages
SocketExceptionSocketOutputStream.socketWrite1818

Connection force closed either by client or server causing write error

java.net.SocketException
2 frames hidden
java.net.SocketOutputStream.write
1804Web pages
1Solution
SocketExceptionSocketOutputStream.write1804

SecureClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
2 frames hidden
java.security.SecureClassLoader.defineClass
1792Web pages
UnsupportedClassVersionErrorSecureClassLoader.defineClass1792

ClassLoader.defineClass() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
1 frames hidden
java.lang.ClassLoader.defineClass
1757Web pages
NoClassDefFoundErrorClassLoader.defineClass1757

ClassLoader.loadClassInternal() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
6 frames hidden
java.lang.ClassLoader.loadClassInternal
1726Web pages
ClassNotFoundExceptionClassLoader.loadClassInternal1726

URLClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
3 frames hidden
java.net.URLClassLoader.defineClass
1696Web pages
UnsupportedClassVersionErrorURLClassLoader.defineClass1696

ClassCastException due to bug in JDK8

java.lang.ClassCastException
sun.java2d.xr.XRPMBlitLoops.cacheToTmpSurface
1678Web pages
1Solution
ClassCastExceptionXRPMBlitLoops.cacheToTmpSurface1678

XrSwToPMBlit.Blit() has thrown a ClassCastException

java.lang.ClassCastException
1 frames hidden
sun.java2d.xr.XrSwToPMBlit.Blit
1677Web pages
ClassCastExceptionXrSwToPMBlit.Blit1677

FileOutputStream.<init>() has thrown a FileNotFoundException

java.io.FileNotFoundException
1 frames hidden
java.io.FileOutputStream.<init>
1674Web pages
FileNotFoundExceptionFileOutputStream.<init>1674

Connection timed out while trying to read from a socket

java.net.SocketTimeoutException
java.net.SocketInputStream.socketRead0
1577Web pages
1Solution
SocketTimeoutExceptionSocketInputStream.socketRead01577

DrawImage.copyImage() has thrown a ClassCastException

java.lang.ClassCastException
5 frames hidden
sun.java2d.pipe.DrawImage.copyImage
1546Web pages
ClassCastExceptionDrawImage.copyImage1546

FileOutputStream.<init>() has thrown a FileNotFoundException

java.io.FileNotFoundException
2 frames hidden
java.io.FileOutputStream.<init>
1468Web pages
FileNotFoundExceptionFileOutputStream.<init>1468
Nothing to list here.
Nothing to list here.
Nothing to list here.
Nothing to list here.