안드로이드 개발

java.lang.UnsupportedOperationException 해결 법

피커 2023. 5. 4. 13:46
728x90
반응형

개발중에 java.lang.UnsupportedOperationException라는 에러를 보게 된다면 아래처럼 해결해보세요.

 

 

1. 오류 코드 (문제 코드)

  -. 아래 코드를 보면 plusNumber함수에서 배열을 추가하고 있습니다.

2. 오류 로그

 -. 실제 실행하고 나면 아래와 같이 에러를 표출하게 됩니다.

3. 해결 방법

아래처럼 코드를 수정하게 되면 문제를 깨끗이 해결됩니다.

파란색 바탕색으로 작성된 코드를 주목해주세요.

 

4. 해결후 logcat 내용

 

 

*. 에러 원문

FATAL EXCEPTION: main
Process: com.picker.javaexception, PID: 21186
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.picker.javaexception/com.picker.javaexception.MainActivity}: java.lang.UnsupportedOperationException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at co m.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at co m.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:153)
at java.util.AbstractList.add(AbstractList.java:111)
at com.picker.javaexception.MainActivity.plusNumber(MainActivity.java:26)
at com.picker.javaexception.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7839) 
at java.lang.reflect.Method.invoke(Native Method) 
at co m.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)  
at co m.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)  

 

*. 익센션 원문

Thrown to indicate that the requested operation is not supported.
This class is a member of the Java Collections Framework.

Summary

 
 

Public constructors

UnsupportedOperationException

Added in API level 1
 
Constructs an UnsupportedOperationException with no detail message.

UnsupportedOperationException

Added in API level 1
 
Constructs an UnsupportedOperationException with the specified detail message.
 

UnsupportedOperationException

Added in API level 1
 
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

Added in API level 1
 
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).
 

 

반응형