![]() |
|
|||||||
| SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
UnsupportedOperation Exception
Gents,
I am getting a Java UnsupportedOperation Exception and I can't figure out why. Details: I have an instance variable: Code:
private List<String> allowedUsers = null; Code:
allowedUsers = new ArrayList<String>(); Code:
String[] StringArray = S.split(D);
return Arrays.asList(StringArray);
Code:
if (allowedUsers.contains(userID)) {
allowedUsers.remove(allowedUsers.indexOf(userID));
}
Code:
if (allowedUsers.contains(userID)) {
allowedUsers.remove(userID);
}
I know I'm doing something really silly, but what? Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
|
#2
|
||||
|
||||
|
While the toList() doesn't explicitly state that the list is readonly (in terms of adding/removing) elements it does say that changes to the list are reflected in the array. Since you can not grow/shrink the array, i'm guessing the you get UnsupportedOperations when you try to add/remove to the list.
To solve... Code:
ArrayList list = new ArrayList(Arrays.asList(YourArray));
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
|
#3
|
||||
|
||||
|
UnsupportedOperation means pretty much what it says. Apparently you're using a nonmutable List implementation that does not support the remove() method. My guess is that it's the List returned from Arrays.asList(), which is not the same as a mutable ArrayList.
The same applies, by the way, to the Lists implemented by my API wrappers. You can index them, search them, and iterate them, but you can't modify them.
__________________
-- Greg |
|
#4
|
||||
|
||||
|
Thanks Sean and Greg. Yes, it's because I'm using Arrays.asList, I didn't realize the resulting List was nonmutable. My noob lesson of the day
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
|
#5
|
||||
|
||||
|
Quote:
Code:
return new ArrayList(Arrays.asList(StringArray)); Code:
warning: [unchecked] unchecked call to ArrayList(java.util.Collection<? extends E>) as a member of the raw type java.util.ArrayList warning: [unchecked] unchecked conversion Here is the entire method: Code:
static List<String> delimitedStringToList(String S, String D) {
List<String> TheList = new ArrayList<String>();
if (S == null || D == null || S.isEmpty()) {
return TheList;
}
String[] StringArray = S.split(D);
if (StringArray == null || StringArray.length==0) {
return TheList;
}
return new ArrayList(Arrays.asList(StringArray));
}
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
|
#6
|
||||
|
||||
|
Quote:
Code:
return new ArrayList<String>(Arrays.asList(StringArray));
__________________
-- Greg |
|
#7
|
||||
|
||||
|
That made it compile cleanly, thanks Greg.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Playback Exception | KipKasper | SageTV Software | 6 | 11-29-2010 06:15 PM |
| Exception errors | bits | Batch Metadata Tools | 4 | 07-04-2010 09:19 PM |
| HDhomeRun playback exception | mattbrad2 | Hardware Support | 3 | 12-15-2006 09:05 AM |
| Stumped at java exception | beelzerob | SageTV Studio | 12 | 07-25-2006 11:46 PM |
| Java Exception | mike1961 | SageTV Software | 0 | 12-20-2005 06:13 PM |