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 unable to establish connection with 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.

DescriptionException TypeEntry MethodWeb pages

The class could not be found

java.lang.ClassNotFoundException
java.net.URLClassLoader.findClass
6745Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6745

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

java.lang.ClassNotFoundException
2 frames hidden
java.net.URLClassLoader.findClass
6454Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6454

Client unable to establish connection with Server

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4763Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4763

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

java.lang.NumberFormatException
java.lang.NumberFormatException.forInputString
4306Web pages
1Solution
NumberFormatExceptionNumberFormatException.forInputString4306

SecurityManager permission too restrictive or unable to find policy file

java.security.AccessControlException
java.security.AccessControlContext.checkPermission
3602Web pages
1Solution
AccessControlExceptionAccessControlContext.checkPermission3602

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

java.io.FileNotFoundException
java.io.FileInputStream.open
3530Web pages
1Solution
FileNotFoundExceptionFileInputStream.open3530

Class version incompatible with current JRE version

java.lang.UnsupportedClassVersionError
java.lang.ClassLoader.defineClass1
3021Web pages
UnsupportedClassVersionErrorClassLoader.defineClass13021

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

java.lang.StringIndexOutOfBoundsException
java.lang.String.substring
2318Web pages
1Solution
StringIndexOutOfBoundsExceptionString.substring2318

Unable to find library file in java library path

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader.loadLibrary
2313Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary2313

Incompatible dependency version or class not found in classpath

java.lang.NoClassDefFoundError
java.lang.ClassLoader.defineClass1
2258Web pages
1Solution
NoClassDefFoundErrorClassLoader.defineClass12258

JNI unable to load native library

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader$NativeLibrary.load
2215Web pages
1Solution
UnsatisfiedLinkErrorClassLoader$NativeLibrary.load2215

Unable to read from socket, server disconnected abruptly

java.net.SocketException
java.net.SocketInputStream.read
1974Web pages
SocketExceptionSocketInputStream.read1974

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

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1824Web pages
SocketExceptionSocketOutputStream.socketWrite01824

Connection timed out while trying to read from a socket

java.net.SocketTimeoutException
java.net.SocketInputStream.socketRead0
1515Web pages
1Solution
SocketTimeoutExceptionSocketInputStream.socketRead01515

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

java.util.zip.ZipException
java.util.zip.ZipFile.open
1435Web pages
ZipExceptionZipFile.open1435

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

java.lang.OutOfMemoryError
java.util.Arrays.copyOf
1390Web pages
1Solution
OutOfMemoryErrorArrays.copyOf1390

Unable to establish connection with server

java.net.ConnectException
sun.nio.ch.SocketChannelImpl.checkConnect
1384Web pages
ConnectExceptionSocketChannelImpl.checkConnect1384

JNI unable to find native library

java.lang.UnsatisfiedLinkError
java.lang.Runtime.loadLibrary
1380Web pages
UnsatisfiedLinkErrorRuntime.loadLibrary1380

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

java.io.NotSerializableException
java.io.ObjectOutputStream.writeObject0
1362Web pages
1Solution
NotSerializableExceptionObjectOutputStream.writeObject01362

ClassCastException due to bug in JDK8

java.lang.ClassCastException
sun.java2d.xr.XRPMBlitLoops.cacheToTmpSurface
1344Web pages
1Solution
ClassCastExceptionXRPMBlitLoops.cacheToTmpSurface1344

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
1276Web pages
1Solution
StringIndexOutOfBoundsExceptionString.charAt1276

ClassLoader.defineClass0() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.lang.ClassLoader.defineClass0
1213Web pages
NoClassDefFoundErrorClassLoader.defineClass01213

Class.forName0() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.lang.Class.forName0
1175Web pages
NoClassDefFoundErrorClass.forName01175

URL.<init>() has thrown a MalformedURLException

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

NativeConstructorAccessorImpl.newInstance0() has thrown a MySQLSyntaxErrorException

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
sun.reflect.NativeConstructorAccessorImpl.newInstance0
1172Web pages
MySQLSyntaxErrorExceptionNativeConstructorAccessorImpl.newInstance01172

ArrayList.RangeCheck() has thrown an IndexOutOfBoundsException

java.lang.IndexOutOfBoundsException
java.util.ArrayList.RangeCheck
1167Web pages
IndexOutOfBoundsExceptionArrayList.RangeCheck1167

FileInputStream.open0() has thrown a FileNotFoundException

java.io.FileNotFoundException
java.io.FileInputStream.open0
1155Web pages
FileNotFoundExceptionFileInputStream.open01155

PlainSocketImpl.socketBind() has thrown a BindException

java.net.BindException
java.net.PlainSocketImpl.socketBind
1019Web pages
BindExceptionPlainSocketImpl.socketBind1019

DriverManager.getConnection() has thrown a SQLException

java.sql.SQLException
java.sql.DriverManager.getConnection
1017Web pages
SQLExceptionDriverManager.getConnection1017

HttpURLConnection.getInputStream() has thrown an IOException

java.io.IOException
sun.net.www.protocol.http.HttpURLConnection.getInputStream
981Web pages
IOExceptionHttpURLConnection.getInputStream981

ArrayList$Itr.checkForComodification() has thrown a ConcurrentModificationException

java.util.ConcurrentModificationException
java.util.ArrayList$Itr.checkForComodification
974Web pages
1Solution
ConcurrentModificationExceptionArrayList$Itr.checkForComodification974

ProcessImpl.create() has thrown an IOException

java.io.IOException
java.lang.ProcessImpl.create
972Web pages
IOExceptionProcessImpl.create972

HashMap$HashIterator.nextEntry() has thrown a ConcurrentModificationException

java.util.ConcurrentModificationException
java.util.HashMap$HashIterator.nextEntry
957Web pages
ConcurrentModificationExceptionHashMap$HashIterator.nextEntry957

UNIXProcess.forkAndExec() has thrown an IOException

java.io.IOException
java.lang.UNIXProcess.forkAndExec
938Web pages
IOExceptionUNIXProcess.forkAndExec938

HttpURLConnection.getInputStream0() has thrown an IOException

java.io.IOException
sun.net.www.protocol.http.HttpURLConnection.getInputStream0
933Web pages
1Solution
IOExceptionHttpURLConnection.getInputStream0933

NativeMethodAccessorImpl.invoke0() has thrown an IllegalArgumentException

java.lang.IllegalArgumentException
sun.reflect.NativeMethodAccessorImpl.invoke0
923Web pages
IllegalArgumentExceptionNativeMethodAccessorImpl.invoke0923

ClassLoader.defineClass1() has thrown a ClassFormatError

java.lang.ClassFormatError
java.lang.ClassLoader.defineClass1
868Web pages
ClassFormatErrorClassLoader.defineClass1868

Class.getDeclaredConstructors0() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.lang.Class.getDeclaredConstructors0
865Web pages
NoClassDefFoundErrorClass.getDeclaredConstructors0865

FloatingDecimal.readJavaFormatString() has thrown a NumberFormatException

java.lang.NumberFormatException
sun.misc.FloatingDecimal.readJavaFormatString
792Web pages
NumberFormatExceptionFloatingDecimal.readJavaFormatString792

URI parsing failed due to un-encoded url string

java.net.URISyntaxException
java.net.URI$Parser.fail
789Web pages
1Solution
URISyntaxExceptionURI$Parser.fail789

Class.getConstructor0() has thrown a NoSuchMethodException

java.lang.NoSuchMethodException
java.lang.Class.getConstructor0
773Web pages
1Solution
NoSuchMethodExceptionClass.getConstructor0773

Net.bind0() has thrown a BindException

java.net.BindException
sun.nio.ch.Net.bind0
751Web pages
BindExceptionNet.bind0751

ErrorHandlerWrapper.createSAXParseException() has thrown a SAXParseException

org.xml.sax.SAXParseException
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException
738Web pages
SAXParseExceptionErrorHandlerWrapper.createSAXParseException738

NativeConstructorAccessorImpl.newInstance0() has thrown a WebDriverException

org.openqa.selenium.WebDriverException
sun.reflect.NativeConstructorAccessorImpl.newInstance0
710Web pages
WebDriverExceptionNativeConstructorAccessorImpl.newInstance0710

UnixFileSystem.createFileExclusively() has thrown an IOException

java.io.IOException
java.io.UnixFileSystem.createFileExclusively
703Web pages
1Solution
IOExceptionUnixFileSystem.createFileExclusively703

Hashtable.put() has thrown a NullPointerException

java.lang.NullPointerException
java.util.Hashtable.put
696Web pages
1Solution
NullPointerExceptionHashtable.put696

NamingManager.getInitialContext() has thrown a NoInitialContextException

javax.naming.NoInitialContextException
javax.naming.spi.NamingManager.getInitialContext
686Web pages
NoInitialContextExceptionNamingManager.getInitialContext686

Class.getDeclaredMethods0() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.lang.Class.getDeclaredMethods0
684Web pages
NoClassDefFoundErrorClass.getDeclaredMethods0684

FileOutputStream.open0() has thrown a FileNotFoundException

java.io.FileNotFoundException
java.io.FileOutputStream.open0
683Web pages
FileNotFoundExceptionFileOutputStream.open0683

ClassLoader.defineClass1() has thrown an IncompatibleClassChangeError

java.lang.IncompatibleClassChangeError
java.lang.ClassLoader.defineClass1
678Web pages
IncompatibleClassChangeErrorClassLoader.defineClass1678
Package namePatterns foundSolution coverageSummary coverage
java.lang40338
java.io3874
java.awt3617
java.util.concurrent3502
java.lang.reflect3465
sun.reflect2112
java.util2073
java.net2070
javax.swing1383
java.security856
javax.naming842
java.sql691
sun.net.www.protocol.http690
sun.net.www.protocol.https681
sun.nio.ch458
java.util.zip290
sun.rmi.server287
java.nio.file266
java.util.regex260
sun.rmi.transport.tcp259
com.sun.jndi.ldap243
com.sun.org.apache.xerces.internal.impl236
com.sun.org.apache.xerces.internal.parsers222
javax.swing.plaf.basic217
sun.net.www.http217
java.util.stream182
sun.misc179
java.util.logging154
com.sun.org.apache.xerces.internal.jaxp151
java.nio148
java.util.jar142
javax.swing.text142
sun.launcher138
java.beans137
java.text133
javax.imageio130
sun.rmi.registry127
javax.net.ssl116
javax.management.remote.rmi116
javax.security.auth.login115
java.rmi114
com.sun.org.apache.xalan.internal.xsltc.trax110
sun.nio.cs110
java.awt.image104
javax.security.auth98
sun.rmi.transport97
java.nio.channels95
sun.instrument92
java.util.concurrent.locks88
java.awt.event86
Package nameClass namePatterns foundSolution coverageSummary coverage
java.langThread34024
java.lang.reflectMethod2743
java.langClassLoader2548
java.langClass2118
java.awtEventDispatchThread2073
sun.reflectNativeMethodAccessorImpl1158
java.util.concurrentThreadPoolExecutor$Worker1067
java.ioObjectInputStream1014
java.util.concurrentFutureTask929
javax.namingInitialContext834
java.sqlDriverManager671
java.util.concurrentExecutors$RunnableAdapter599
sun.net.www.protocol.httpHttpURLConnection597
java.awtEventQueue572
java.lang.reflectConstructor551
java.ioObjectOutputStream533
javax.swingJComponent485
java.securityAccessController471
sun.reflectDelegatingMethodAccessorImpl450
sun.net.www.protocol.httpsHttpsURLConnectionImpl388
java.utilTimerThread376
java.netSocket366
sun.reflectNativeConstructorAccessorImpl337
java.netURLClassLoader293
java.langString288
java.awtContainer281
java.netURL260
java.ioBufferedInputStream253
java.util.concurrentThreadPoolExecutor243
java.langThrowable242
sun.net.www.protocol.httpsAbstractDelegateHttpsURLConnection237
java.util.concurrentForkJoinWorkerThread225
java.nio.fileFiles211
java.ioBufferedOutputStream205
sun.net.www.httpHttpClient202
java.awtComponent194
sun.rmi.serverUnicastRef190
java.ioFile184
java.ioBufferedReader174
java.ioDataInputStream165
java.utilArrays164
java.langRuntime161
java.utilArrayList160
java.netPlainSocketImpl159
java.langSystem159
java.netInetAddress153
java.util.concurrentForkJoinTask135
java.ioFilterInputStream132
java.utilHashMap126
java.netURLClassLoader$1114
Package nameClass nameMethod namePatterns foundSolution coverage
java.langThreadrun33900
java.lang.reflectMethodinvoke2654
java.awtEventDispatchThreadrun1843
java.langClassLoaderloadClass1700
java.util.concurrentThreadPoolExecutor$Workerrun1055
java.util.concurrentFutureTaskrun831
sun.reflectNativeMethodAccessorImplinvoke0751
java.langClassforName681
java.sqlDriverManagergetConnection654
java.util.concurrentExecutors$RunnableAdaptercall599
javax.namingInitialContextlookup500
java.lang.reflectConstructornewInstance498
java.securityAccessControllerdoPrivileged457
sun.reflectDelegatingMethodAccessorImplinvoke446
sun.reflectNativeMethodAccessorImplinvoke407
java.utilTimerThreadrun368
java.langClassLoaderloadClassInternal366
java.ioObjectInputStreamreadObject0335
java.ioObjectInputStreamreadObject332
java.awtEventQueuedispatchEventImpl281
sun.net.www.protocol.httpHttpURLConnectiongetInputStream277
javax.swingJComponentpaint246
java.langClassnewInstance243
java.awtEventQueuedispatchEvent237
sun.reflectNativeConstructorAccessorImplnewInstance0226
java.util.concurrentForkJoinWorkerThreadrun225
sun.net.www.protocol.httpsAbstractDelegateHttpsURLConnectionconnect213
javax.namingInitialContext<init>207
java.ioObjectOutputStreamwriteObject0204
java.netSocketconnect193
java.util.concurrentThreadPoolExecutorrunWorker190
java.langClassLoaderdefineClass188
java.ioObjectOutputStreamwriteObject177
java.netURLopenStream162
java.ioBufferedInputStreamread160
sun.rmi.serverUnicastRefinvoke132
java.netURLClassLoaderfindClass129
java.langClassprivateGetDeclaredMethods129
java.util.concurrentForkJoinTaskdoExec124
sun.net.www.protocol.httpsHttpsURLConnectionImplgetInputStream120
java.ioFilterInputStreamread119
java.langClassLoaderdefineClass1118
java.netURLClassLoader$1run114
sun.reflectNativeConstructorAccessorImplnewInstance111
java.netSocket<init>110
sun.reflectDelegatingConstructorAccessorImplnewInstance110
java.langRuntimeexec110
java.langClassgetDeclaredMethods109
java.ioBufferedReaderreadLine106
java.langClassgetConstructor0103
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
java.langThreadrunNullPointerException2263
java.langThreadrunRuntimeException1631
java.langThreadrunIllegalStateException1458
java.langThreadrunIOException1365
java.langThreadrunIllegalArgumentException994
java.langThreadrunFileNotFoundException619
java.langThreadrunSessionNotCreatedException561
java.langThreadrunNoClassDefFoundError554
java.langClassLoaderloadClassClassNotFoundException523
java.langThreadrunClassNotFoundException514
java.langThreadrunWebDriverException501
java.langThreadrunServletException478
java.langThreadrunClassCastException449
java.langThreadrunMissingPropertyException446
java.langThreadrunBeanCreationException394
java.langThreadrunSQLException391
java.awtEventDispatchThreadrunNullPointerException381
java.langThreadrunException363
java.langClassLoaderloadClassNoClassDefFoundError351
java.langThreadrunInvocationTargetException349
java.langThreadrunNoSuchMethodError335
java.lang.reflectMethodinvokeNullPointerException316
java.langThreadrunSparkException291
java.langThreadrunSocketException276
java.langThreadrunExecutionException276
java.langThreadrunConnectException256
java.sqlDriverManagergetConnectionSQLException247
java.lang.reflectMethodinvokeIllegalStateException247
java.langClassforNameClassNotFoundException234
java.langThreadrunOAException232
java.langThreadrunLifecycleException222
java.langThreadrunThrowable214
java.langThreadrunAssertionError201
java.langThreadrunArrayIndexOutOfBoundsException193
java.lang.reflectMethodinvokeRuntimeException186
java.langThreadrunOutOfMemoryError185
java.langThreadrunSocketTimeoutException178
java.langThreadrunJSONException177
java.langThreadrunJasperException165
java.langThreadrunNumberFormatException158
java.langClassforNameNoClassDefFoundError153
javax.namingInitialContextlookupNameNotFoundException149
java.langThreadrunIndexOutOfBoundsException142
java.util.concurrentThreadPoolExecutor$WorkerrunNullPointerException140
java.langThreadrunEOFException139
java.langThreadrunSecurityException138
java.ioObjectOutputStreamwriteObject0NotSerializableException136
java.lang.reflectMethodinvokeIllegalArgumentException132
java.langThreadrunPSQLException129
java.lang.reflectMethodinvokeInvocationTargetException128