- Java lang unsupportedoperationexception null
- Constructor Summary
- Method Summary
- Methods declared in class java.lang.Throwable
- Methods declared in class java.lang.Object
- Constructor Detail
- UnsupportedOperationException
- UnsupportedOperationException
- UnsupportedOperationException
- UnsupportedOperationException
- Class UnsupportedOperationException
- Constructor Summary
- Method Summary
- Methods declared in class java.lang.Throwable
- Methods declared in class java.lang.Object
- Constructor Details
- UnsupportedOperationException
- UnsupportedOperationException
- UnsupportedOperationException
- UnsupportedOperationException
- java.lang.UnsupportedOperationException – How to handle UnsupportedOperationException
- The Structure of UnsupportedOperationException
- Constructors
- The UnsupportedOperationException in Java
- How to deal with the UnsupportedOperationException
- Download the Eclipse Project
- Unsupported Operation Exception Class
- Remarks
- Constructors
- Fields
- Properties
- Methods
- Explicit Interface Implementations
- Extension Methods
Java lang unsupportedoperationexception null
Thrown to indicate that the requested operation is not supported. This class is a member of the Java Collections Framework.
Constructor Summary
Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause ).
Method Summary
Methods declared in class java.lang.Throwable
Methods declared in class java.lang.Object
Constructor Detail
UnsupportedOperationException
public UnsupportedOperationException()
UnsupportedOperationException
UnsupportedOperationException
Constructs a new exception with the specified detail message and cause. Note that the detail message associated with cause is not automatically incorporated in this exception’s detail message.
UnsupportedOperationException
Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause ). This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, PrivilegedActionException ).
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Class UnsupportedOperationException
This class is a member of the Java Collections Framework.
Constructor Summary
Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause ).
Method Summary
Methods declared in class java.lang.Throwable
Methods declared in class java.lang.Object
Constructor Details
UnsupportedOperationException
UnsupportedOperationException
UnsupportedOperationException
Constructs a new exception with the specified detail message and cause. Note that the detail message associated with cause is not automatically incorporated in this exception’s detail message.
UnsupportedOperationException
Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause ). This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, PrivilegedActionException ).
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
java.lang.UnsupportedOperationException – How to handle UnsupportedOperationException
In this tutorial we will discuss about UnsupportedOperationException in Java. This exception is thrown to indicate that the requested operation is not supported. This exception extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method’s or a constructor’s throws clause. Moreover, the UnsupportedOperationException exists since the 1.2 version of Java. Finally, the UnsupportedOperationException is a member of the Java Collections Framework.
The Structure of UnsupportedOperationException
Constructors
Creates an instance of the UnsupportedOperationException class, setting null as its message.
Creates an instance of the UnsupportedOperationException class, using the specified string as message. The string argument indicates the name of the class that threw the error.
Creates an instance of the UnsupportedOperationException class, using the specified parameters as message cause respectively.
The UnsupportedOperationException in Java
The UnsupportedOperationException indicates that the requested operation cannot be performed, due to the fact that it is forbidden for that particular class. The following methods create unmodifiable views of different collections:
These views are read-only and thus, cannot be modified. If an application tries to modify such view, an UnsupportedOperationException is thrown. The following examples indicate the aforementioned cases:
UnsupportedOperationExceptionExample_Collection.java:
import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Random; public class UnsupportedOperationExceptionExampleCollection < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < Collection integers = new HashSet(TOTAL_ELEMS); // Fill the collection with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) integers.add(random.nextInt()); // Retrieve an unmodifiable view of the collection. Collection unmodifiableCollection = Collections.unmodifiableCollection(integers); // This statement throws an UnsupportedOperationException. unmodifiableCollection.add(random.nextInt()); >>
In this example, we created an instance of the HashSet class, which implements the Collection interface, and inserted a number of random values. Then, we retrieved an unmodifiable view of the Collection and tried to insert a new element, which resulted to an UnsupportedOperationException .
UnsupportedOperationExceptionExampleSet.java:
import java.util.Collections; import java.util.HashSet; import java.util.Random; import java.util.Set; public class UnsupportedOperationExceptionExampleSet < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < Set integers = new HashSet(TOTAL_ELEMS); // Fill the set with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) integers.add(random.nextInt()); // Retrieve an unmodifiable view of the set. Set unmodifiableSet = Collections.unmodifiableSet(integers); // This statement throws an UnsupportedOperationException. unmodifiableSet.add(random.nextInt()); >>
In this example, we created an instance of the HashSet class and inserted a number of random values. Then, we retrieved an unmodifiable view of the HashSet and tried to insert a new element, which resulted to an UnsupportedOperationException .
UnsupportedOperationExceptionExampleSortedSet.java:
import java.util.Collections; import java.util.Random; import java.util.SortedSet; import java.util.TreeSet; public class UnsupportedOperationExceptionExampleSortedSet < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < TreeSet integers = new TreeSet(); // Fill the tree set with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) integers.add(random.nextInt()); // Retrieve an unmodifiable view of the tree set. SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(integers); // This statement throws an UnsupportedOperationException. unmodifiableSortedSet.add(random.nextInt()); >>
In this example, we created an instance of the TreeSet class and inserted a number of random values. Then, we retrieved an unmodifiable view of the TreeSet and tried to insert a new element, which resulted to an UnsupportedOperationException .
UnsupportedOperationExceptionExampleList.java:
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; public class UnsupportedOperationExceptionExampleList < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < List integers = new ArrayList(TOTAL_ELEMS); // Fill the list with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) integers.add(random.nextInt()); // Retrieve an unmodifiable view of the list. List unmodifiableList = Collections.unmodifiableList(integers); // This statement throws an UnsupportedOperationException. unmodifiableList.add(random.nextInt()); >>
In this example, we created an instance of the ArrayList class and inserted a number of random values. Then, we retrieved an unmodifiable view of the ArrayList and tried to insert a new element, which resulted to an UnsupportedOperationException .
UnsupportedOperationExceptionExampleMap.java:
import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Random; public class UnsupportedOperationExceptionExampleMap < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < Map map = new HashMap(); // Fill the map with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) map.put(("key_" + i), random.nextInt()); // Retrieve an unmodifiable view of the map. Map unmodifiableMap = Collections.unmodifiableMap(map); // This statement throws an UnsupportedOperationException. unmodifiableMap.put("KEY", random.nextInt()); >>
In this example, we created an instance of the HashMap class and inserted a number of random values. Then, we retrieved an unmodifiable view of the HashMap and tried to insert a new element, which resulted to an UnsupportedOperationException .
UnsupportedOperationExceptionExampleSortedMap.java:
import java.util.Collections; import java.util.Random; import java.util.SortedMap; import java.util.TreeMap; public class UnsupportedOperationExceptionExampleSortedMap < private final static int TOTAL_ELEMS = 10; private final static Random random = new Random(); public static void main(String[] args) < TreeMap map = new TreeMap(); // Fill the tree map with some random values. for(int i = 0; i < TOTAL_ELEMS; ++i) map.put(("key_" + i), random.nextInt()); // Retrieve an unmodifiable view of the tree map. SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(map); // This statement throws an UnsupportedOperationException. unmodifiableSortedMap.put("KEY", random.nextInt()); >>
In this example, we created an instance of the TreeMap class and inserted a number of random values. Then, we retrieved an unmodifiable view of the TreeMap and tried to insert a new element, which resulted to an UnsupportedOperationException .
How to deal with the UnsupportedOperationException
- This exception is easy to deal with, because it indicates which method cannot be used. Thus, if your application requires the modification of some collection or data structures, you shall avoid using unmodifiable views.
- Also, if this exception is thrown by a class of an external library, you shall consult its documentation, in order to understand why this particular exception is thrown.
Download the Eclipse Project
This was a tutorial about the UnsupportedOperationException in Java.
Unsupported Operation Exception Class
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Thrown to indicate that the requested operation is not supported.
[Android.Runtime.Register("java/lang/UnsupportedOperationException", DoNotGenerateAcw=true)] public class UnsupportedOperationException : Java.Lang.RuntimeException
[] type UnsupportedOperationException = class inherit RuntimeException
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
Constructs an UnsupportedOperationException with no detail message.
A constructor used when creating managed representations of JNI objects; called by the runtime.
Constructs an UnsupportedOperationException with the specified detail message.
Constructs a new exception with the specified detail message and cause.
Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause ).
Fields
Properties
Returns the cause of this throwable or null if the cause is nonexistent or unknown.
The handle to the underlying Android instance.
Creates a localized description of this throwable.
Returns the detail message string of this throwable.
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
Methods
Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.
Fills in the execution stack trace.
Provides programmatic access to the stack trace information printed by #printStackTrace() .
Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception.
Initializes the cause of this throwable to the specified value.
Prints this throwable and its backtrace to the standard error stream.
Prints this throwable and its backtrace to the specified print stream.
Prints this throwable and its backtrace to the specified print writer.
Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTrace() and related methods.
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Throwable) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Throwable) |
IJavaPeerable.Finalized() | (Inherited from Throwable) |
IJavaPeerable.JniManagedPeerState | (Inherited from Throwable) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Throwable) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Throwable) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Throwable) |
Extension Methods
Performs an Android runtime-checked type conversion.