Top Description Fields Constructors Methods
java.lang

public Class ClassNotFoundException

extends ReflectiveOperationException
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField

Thrown when an application tries to load in a class through its string name using:

but no definition for the class with the specified name could be found.

Since
1.0
See Also
java.lang.Class#forName(java.lang.String), java.lang.ClassLoader#findSystemClass(java.lang.String), java.lang.ClassLoader#loadClass(java.lang.String, boolean)

Field Summary

Modifier and TypeField and Description
private static final ObjectStreamField[]
serialPersistentFields

Serializable fields for ClassNotFoundException.

private static final long
serialVersionUID

Hides java.lang.ReflectiveOperationException.serialVersionUID.

use serialVersionUID from JDK 1.1.X for interoperability

Constructor Summary

AccessConstructor and Description
public
ClassNotFoundException()

Constructs a ClassNotFoundException with no detail message.

public
ClassNotFoundException(String
the detail message.
s
)

Constructs a ClassNotFoundException with the specified detail message.

public
ClassNotFoundException(String
the detail message
s
,
Throwable
the exception that was raised while loading the class
ex
)

Constructs a ClassNotFoundException with the specified detail message and optional exception that was raised while loading the class.

Method Summary

Modifier and TypeMethod and Description
public Throwable

Returns:

the Exception that was raised while loading a class
getException
()

Returns the exception that was raised if an error occurred while attempting to load the class.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
s
)

Hides java.lang.Throwable.readObject.

Reconstitutes the ClassNotFoundException instance from a stream and initialize the cause properly when deserializing from an older version.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
out
)

Hides java.lang.Throwable.writeObject.

To maintain compatibility with older implementation, write a serial "ex" field with the cause as the value.

Field Detail

serialPersistentFieldsback to summary
private static final ObjectStreamField[] serialPersistentFields

Serializable fields for ClassNotFoundException.

Annotations
@Serial
Serial Fields:
ex:Throwable
the Throwable
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.ReflectiveOperationException.serialVersionUID.

use serialVersionUID from JDK 1.1.X for interoperability

Annotations
@Serial

Constructor Detail

ClassNotFoundExceptionback to summary
public ClassNotFoundException()

Constructs a ClassNotFoundException with no detail message.

ClassNotFoundExceptionback to summary
public ClassNotFoundException(String s)

Constructs a ClassNotFoundException with the specified detail message.

Parameters
s:String

the detail message.

ClassNotFoundExceptionback to summary
public ClassNotFoundException(String s, Throwable ex)

Constructs a ClassNotFoundException with the specified detail message and optional exception that was raised while loading the class.

Parameters
s:String

the detail message

ex:Throwable

the exception that was raised while loading the class

Since
1.2

Method Detail

getExceptionback to summary
public Throwable getException()

Returns the exception that was raised if an error occurred while attempting to load the class. Otherwise, returns null.

API Note

This method predates the general-purpose exception chaining facility. The Throwable#getCause() method is now the preferred means of obtaining this information.

Returns:Throwable

the Exception that was raised while loading a class

Since
1.2
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides java.lang.Throwable.readObject.

Reconstitutes the ClassNotFoundException instance from a stream and initialize the cause properly when deserializing from an older version. The getException and getCause method returns the private "ex" field in the older implementation and ClassNotFoundException::cause was set to null.

Parameters
s:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException

Hides java.lang.Throwable.writeObject.

To maintain compatibility with older implementation, write a serial "ex" field with the cause as the value.

Parameters
out:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs