»

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
6981Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6981

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

java.lang.ClassNotFoundException
2 frames hidden
java.net.URLClassLoader.findClass
6459Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6459

Client cannot establish connection with the server

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4815Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4815

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

java.lang.NumberFormatException
java.lang.NumberFormatException.forInputString
4352Web pages
1Solution
NumberFormatExceptionNumberFormatException.forInputString4352

SecurityManager permission too restrictive or unable to find policy file

java.security.AccessControlException
java.security.AccessControlContext.checkPermission
3618Web pages
1Solution
AccessControlExceptionAccessControlContext.checkPermission3618

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

java.io.FileNotFoundException
java.io.FileInputStream.open
3539Web pages
1Solution
FileNotFoundExceptionFileInputStream.open3539

Class version incompatible with current JRE version

java.lang.UnsupportedClassVersionError
java.lang.ClassLoader.defineClass1
3056Web pages
UnsupportedClassVersionErrorClassLoader.defineClass13056

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

java.lang.StringIndexOutOfBoundsException
java.lang.String.substring
2358Web pages
1Solution
StringIndexOutOfBoundsExceptionString.substring2358

Unable to find library file in java library path

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader.loadLibrary
2331Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary2331

Incompatible dependency version or class not found in classpath

java.lang.NoClassDefFoundError
java.lang.ClassLoader.defineClass1
2267Web pages
1Solution
NoClassDefFoundErrorClassLoader.defineClass12267

JNI unable to load native library

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader$NativeLibrary.load
2253Web pages
1Solution
UnsatisfiedLinkErrorClassLoader$NativeLibrary.load2253

Unable to read from socket, server disconnected abruptly

java.net.SocketException
java.net.SocketInputStream.read
2000Web pages
SocketExceptionSocketInputStream.read2000

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

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1835Web pages
SocketExceptionSocketOutputStream.socketWrite01835

ClassCastException due to bug in JDK8

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

Connection timed out while trying to read from a socket

java.net.SocketTimeoutException
java.net.SocketInputStream.socketRead0
1549Web pages
1Solution
SocketTimeoutExceptionSocketInputStream.socketRead01549

Empty/Corrupted zip file or file not found in the path provided

java.util.zip.ZipException
java.util.zip.ZipFile.open
1446Web pages
ZipExceptionZipFile.open1446

JVM ran out of heap space while trying to create a copy of an existing array

java.lang.OutOfMemoryError
java.util.Arrays.copyOf
1420Web pages
1Solution
OutOfMemoryErrorArrays.copyOf1420

Unable to establish connection with server

java.net.ConnectException
sun.nio.ch.SocketChannelImpl.checkConnect
1399Web pages
ConnectExceptionSocketChannelImpl.checkConnect1399

JNI unable to find native library

java.lang.UnsatisfiedLinkError
java.lang.Runtime.loadLibrary
1396Web pages
UnsatisfiedLinkErrorRuntime.loadLibrary1396

Trying to write an object to a file/socket that is not serializable

java.io.NotSerializableException
java.io.ObjectOutputStream.writeObject0
1377Web pages
1Solution
NotSerializableExceptionObjectOutputStream.writeObject01377

The index provided to String's charAt() method is either greater or equal to the size of the String or less than 0

java.lang.StringIndexOutOfBoundsException
java.lang.String.charAt
1283Web pages
1Solution
StringIndexOutOfBoundsExceptionString.charAt1283

Error in MySql query syntax

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
sun.reflect.NativeConstructorAccessorImpl.newInstance0
1188Web pages
MySQLSyntaxErrorExceptionNativeConstructorAccessorImpl.newInstance01188

URL not properly encoded or incorrect URL format

java.net.MalformedURLException
java.net.URL.<init>
1183Web pages
MalformedURLExceptionURL.<init>1183

Class not found in classpath, for the class referenced in Class.forName() method

java.lang.NoClassDefFoundError
java.lang.Class.forName0
1177Web pages
NoClassDefFoundErrorClass.forName01177

Index provided to the ArrayList method is either greater or equal to size of the list or less than 0

java.lang.IndexOutOfBoundsException
java.util.ArrayList.RangeCheck
1169Web pages
IndexOutOfBoundsExceptionArrayList.RangeCheck1169

NativeMethodAccessorImpl.invoke() has thrown an InvocationTargetException

java.lang.reflect.InvocationTargetException
1 frames hidden
sun.reflect.NativeMethodAccessorImpl.invoke
1044Web pages
1Solution
InvocationTargetExceptionNativeMethodAccessorImpl.invoke1044

Multiple threads trying to modify ArrayList at the same time or trying to modify ArrayList while iterating over it

java.util.ConcurrentModificationException
java.util.ArrayList$Itr.checkForComodification
1035Web pages
1Solution
ConcurrentModificationExceptionArrayList$Itr.checkForComodification1035

Unable to find suitable driver to create connection with database server

java.sql.SQLException
java.sql.DriverManager.getConnection
1024Web pages
1Solution
SQLExceptionDriverManager.getConnection1024

Port already in use

java.net.BindException
java.net.PlainSocketImpl.socketBind
1021Web pages
BindExceptionPlainSocketImpl.socketBind1021

Trying to modify a HashMap directly while iterating over it

java.util.ConcurrentModificationException
java.util.HashMap$HashIterator.nextEntry
959Web pages
1Solution
ConcurrentModificationExceptionHashMap$HashIterator.nextEntry959

ProcessBuilder/Runtime unable to create process

java.io.IOException
1 frames hidden
java.lang.ProcessImpl.<init>
958Web pages
IOExceptionProcessImpl.<init>958

Error using java Reflections, argument mismatch or provided object is not an instance of the expected class

java.lang.IllegalArgumentException
sun.reflect.NativeMethodAccessorImpl.invoke0
930Web pages
1Solution
IllegalArgumentExceptionNativeMethodAccessorImpl.invoke0930

ProcessImpl.start() has thrown an IOException

java.io.IOException
2 frames hidden
java.lang.ProcessImpl.start
881Web pages
IOExceptionProcessImpl.start881

Trying to run application as standalone instead of inside a container or application server

java.lang.ClassFormatError
java.lang.ClassLoader.defineClass1
873Web pages
ClassFormatErrorClassLoader.defineClass1873

Missing jar file containing class in WEB-INF/lib directory of the project

java.lang.NoClassDefFoundError
java.lang.Class.getDeclaredConstructors0
867Web pages
NoClassDefFoundErrorClass.getDeclaredConstructors0867

Provided String does not consist of real numbers

java.lang.NumberFormatException
sun.misc.FloatingDecimal.readJavaFormatString
799Web pages
NumberFormatExceptionFloatingDecimal.readJavaFormatString799

URI parsing failed due to un-encoded url string

java.net.URISyntaxException
java.net.URI$Parser.fail
799Web pages
1Solution
URISyntaxExceptionURI$Parser.fail799

Class.getConstructor0() has thrown a NoSuchMethodException

java.lang.NoSuchMethodException
java.lang.Class.getConstructor0
793Web pages
1Solution
NoSuchMethodExceptionClass.getConstructor0793

Connection trying to bind to an address already in use

java.net.BindException
sun.nio.ch.Net.bind0
770Web pages
BindExceptionNet.bind0770

Unable to create/append to file

java.io.FileNotFoundException
java.io.FileOutputStream.open0
714Web pages
1Solution
FileNotFoundExceptionFileOutputStream.open0714

JRE unable to create file

java.io.IOException
java.io.UnixFileSystem.createFileExclusively
713Web pages
1Solution
IOExceptionUnixFileSystem.createFileExclusively713

Trying to add an entry to a null HashTable

java.lang.NullPointerException
java.util.Hashtable.put
705Web pages
1Solution
NullPointerExceptionHashtable.put705

NativeConstructorAccessorImpl.newInstance() has thrown a WebDriverException

org.openqa.selenium.WebDriverException
1 frames hidden
sun.reflect.NativeConstructorAccessorImpl.newInstance
700Web pages
WebDriverExceptionNativeConstructorAccessorImpl.newInstance700

Unable to load the provided class through reflection

java.lang.NoClassDefFoundError
java.lang.Class.getDeclaredMethods0
687Web pages
1Solution
NoClassDefFoundErrorClass.getDeclaredMethods0687

Unable to load provided class or class name is null

javax.naming.NoInitialContextException
javax.naming.spi.NamingManager.getInitialContext
687Web pages
NoInitialContextExceptionNamingManager.getInitialContext687

Conflict between library/dependency versions

java.lang.IncompatibleClassChangeError
java.lang.ClassLoader.defineClass1
686Web pages
IncompatibleClassChangeErrorClassLoader.defineClass1686

Unable to retrieve method from class using reflection

java.lang.NoSuchMethodException
java.lang.Class.getMethod
667Web pages
1Solution
NoSuchMethodExceptionClass.getMethod667

Class version not compatible with JRE

java.lang.UnsupportedClassVersionError
java.lang.ClassLoader.defineClass0
644Web pages
UnsupportedClassVersionErrorClassLoader.defineClass0644

Source and target array size mismatch, trying to copy an array of larger size to a smaller one

java.lang.ArrayIndexOutOfBoundsException
java.lang.System.arraycopy
642Web pages
ArrayIndexOutOfBoundsExceptionSystem.arraycopy642

No matching ENUM found for the given string

java.lang.IllegalArgumentException
java.lang.Enum.valueOf
641Web pages
1Solution
IllegalArgumentExceptionEnum.valueOf641
Nothing to list here.
Nothing to list here.
Nothing to list here.
Nothing to list here.