标签: unsupportedoperation

Java List.add()UnsupportedOperationException

我尝试将对象添加到List<String>实例,但它会抛出一个UnsupportedOperationException.有谁知道为什么?

我的Java代码:

String[] membersArray = request.getParameterValues('members');
List<String> membersList = Arrays.asList(membersArray);

for (String member : membersList) {
    Person person = Dao.findByName(member);
    List<String> seeAlso;
    seeAlso = person.getSeeAlso();
    if (!seeAlso.contains(groupDn)){
        seeAlso.add(groupDn);
        person.setSeeAlso(seeAlso);
    }
}
Run Code Online (Sandbox Code Playgroud)

错误消息:

java.lang.UnsupportedOperationException
    java.util.AbstractList.add(Unknown Source)
    java.util.AbstractList.add(Unknown Source)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

java exception list arraylist unsupportedoperation

197
推荐指数
3
解决办法
12万
查看次数

java.lang.UnsupportedOperationException:'posix:permissions'不支持作为Windows上的初始属性

我正在使用Java 7 File API.我编写了一个在Ubuntu上完美地创建目录的类,但是当我在Windows上运行相同的代码时,它会抛出错误:

Exception in thread "main" java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
    at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.createDirectory(Unknown Source)
    at java.nio.file.Files.createDirectory(Unknown Source)
    at java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
    at java.nio.file.Files.createDirectories(Unknown Source)
    at com.cloudspoke.folder_permission.Folder.createFolder(Folder.java:27)
    at com.cloudspoke.folder_permission.Main.main(Main.java:139)
Run Code Online (Sandbox Code Playgroud)

我的文件夹类代码是

package com.cloudspoke.folder_permission;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.Set;

public class Folder{
    // attributes required for creating a Folder
    private UserPrincipal owner;
    private Path folder_name;
    private FileAttribute<Set<PosixFilePermission>> attr;


    public Folder(UserPrincipal owner,Path folder_name,FileAttribute<Set<PosixFilePermission>> attr){
        this.owner=owner;
        this.folder_name=folder_name;
        this.attr=attr;
    }
    //invoking …
Run Code Online (Sandbox Code Playgroud)

java nio java-io java-7 unsupportedoperation

15
推荐指数
1
解决办法
2万
查看次数

在列表中使用.view时出现奇怪的异常

我有很多数字.我需要对它们应用一些操作,然后只获取满足某些条件的结果.列表是顺序的,所以一旦我找到不满足条件的数字,我就可以停止查找.

我想避免做太多的计算,所以我在这个例子中继续前进:

List(1,2,3,4,5).view.map(2 *).takeWhile(_ < 8)
Run Code Online (Sandbox Code Playgroud)

但它给了我一个例外:

java.lang.UnsupportedOperationException: SeqViewM(...).newBuilder
at scala.collection.TraversableViewLike$class.newBuilder(TraversableViewLike.scala:69)
at scala.collection.SeqViewLike$$anon$3.newBuilder(SeqViewLike.scala:77)
at scala.collection.IterableLike$class.takeWhile(IterableLike.scala:139)
at scala.collection.SeqViewLike$$anon$3.takeWhile(SeqViewLike.scala:77)
at scala.collection.SeqViewLike$$anon$3.takeWhile(SeqViewLike.scala:77)
Run Code Online (Sandbox Code Playgroud)

使用Scala 2.9.0.1(与2.9.1相同的行为).这有什么不对?

scala unsupportedoperation

7
推荐指数
1
解决办法
104
查看次数

Map <K,V> .keySet()不支持add/addAll操作

关于Map<K,V>界面:

为什么keySet()返回Set支持remove操作但不支持add()addAll()操作?

java dictionary set keyset unsupportedoperation

7
推荐指数
1
解决办法
955
查看次数

如何知道List.remove()是否"不支持"?

我有这个:

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
public class ListTest {

    public static void main(String[] args) {


        String[] values = { "yes", "no"};
        List<String> aa = Arrays.asList(values);
        System.out.println(aa.getClass().getName());
        aa.remove(0);
    }

}
Run Code Online (Sandbox Code Playgroud)

它给:

$ java ListTest 
java.util.Arrays$ArrayList
Exception in thread "main" java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:161)
    at ListTest.main(ListTest.java:12)
Run Code Online (Sandbox Code Playgroud)

问题:我理解为什么我会得到这个例外.这是因为正在使用ArrayList内部的类Arrays.java没有remove()方法.我的问题是,如果有人(任何用户,像我一样)在使用之前知道List他们收到的是什么,它不包含remove方法?

java list unsupportedoperation

5
推荐指数
1
解决办法
141
查看次数

如果我从来不打算让我的类在基于哈希的集合中使用,我是否应该在 hashCode() 中抛出 UnsupportedOperationException?

HashMap这是一个很好的设计模式来强制一个类不在任何基于散列的集合( 、、HashSet等)中使用,或者这可能会产生意想不到的后果吗?

class DoNotUseInHashBasedCollection {
    @Override
    public int hashCode() {
        throw new UnsupportedOperationException();
    }
}
Run Code Online (Sandbox Code Playgroud)

java hashcode unsupportedoperation

5
推荐指数
0
解决办法
191
查看次数

java.lang.UnsupportedOperationException 用于从 javafx 表视图中删除一行

我正在尝试从 javafx 中的表视图中删除所选记录。下面是我如何用数据填充表:

public void setMainApp(MainAppClass mainApp){
    this.mainApp = mainApp;

    FilteredList<FileModel> filteredData = new FilteredList<>(mainApp.getFileData(), p -> true);

    // 2. Set the filter Predicate whenever the filter changes.
    filterField.textProperty().addListener((observable, oldValue, newValue) -> {
        filteredData.setPredicate(files -> {
            // If filter text is empty, display all files.
            if (newValue == null || newValue.isEmpty()) {
                return true;
            }

            String lowerCaseFilter = newValue.toLowerCase();
            if (files.getFileSubject().toLowerCase().indexOf(lowerCaseFilter) != -1) {
                return true; // Filter matches Subject.
            }
                else if (files.getFileDate().toLowerCase().indexOf(lowerCaseFilter) != -1) {
                return true; // …
Run Code Online (Sandbox Code Playgroud)

java javafx unsupportedoperation

2
推荐指数
1
解决办法
3767
查看次数

Android - GCMRegistrar.checkDevice()中的UnSupportedOperation异常

我正在开发一个Android应用程序,我想在其中实现GCM功能.我能够实现它在Android Kitkat 4.4版本(在Micromax 089上测试)工作正常.但不适用于在Android Lolipop(Android 5.0)及更高版本上运行的设备(如Lava Iris Fuel F1Moto x play).

我用于验证设备依赖性和清单权限的代码片段

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
                DISPLAY_MESSAGE_ACTION));
Run Code Online (Sandbox Code Playgroud)

而应用程序崩溃了 GCMRegistrar.checkDevice(this);

Logcat的屏幕截图.

Logcat的屏幕截图

通过一些研究,我发现了下面列出的一些原因,应用程序可能会崩溃

  1. 该应用可能不会定位到Google API.
  2. 可能未安装Google Play服务.
  3. 互联网可能无法使用.
  4. 与自己的服务器的连接可能已关闭.

即使我已经验证了上述所有情况,也无法解决问题.

请帮我找到解决方案.

android push-notification google-cloud-messaging unsupportedoperation android-5.0-lollipop

2
推荐指数
1
解决办法
200
查看次数

&gt;&gt; 不支持的操作数类型:'builtin_function_or_method' 和 '_io.TextIOWrapper'

这是我的代码:

def _parse(self, text):
    """
    This is the core interaction with the parser.

    It returns a Python data-structure, while the parse()
    function returns a JSON object
    """

    # CoreNLP interactive shell cannot recognize newline
    if '\n' in text or '\r' in text:
        to_send = re.sub("[\r\n]", " ", text).strip()
    else:
        to_send = text


    self.corenlp.sendline(to_send)
    max_expected_time = max(300.0, len(to_send) / 3.0)

    # repeated_input = self.corenlp.except("\n")  # confirm it
    t = self.corenlp.expect(["\nNLP> ", pexpect.TIMEOUT, pexpect.EOF,
                                 "\nWARNING: Parsing of sentence failed, possibly because of …
Run Code Online (Sandbox Code Playgroud)

python json unsupportedoperation

2
推荐指数
1
解决办法
5816
查看次数

java.util.AbstractList.remove 处的 java.lang.UnsupportedOperationException

我正在尝试删除 a 的一项List

list.remove(key);
Run Code Online (Sandbox Code Playgroud)

但是,它会抛出异常:

Caused by: java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:161)
    at java.util.AbstractList$Itr.remove(AbstractList.java:374)
    at java.util.AbstractCollection.remove(AbstractCollection.java:293)
    at bean.Bean.deleteRow(Bean.java:46)
Run Code Online (Sandbox Code Playgroud)

这是如何引起的以及如何解决?

java list unsupportedoperation

2
推荐指数
1
解决办法
1851
查看次数