Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.UnsupportedOperationException:_Java - Fatal编程技术网

java.lang.UnsupportedOperationException:

java.lang.UnsupportedOperationException:,java,Java,在这个程序中,我将属性存储到arraylist public static void main(String [] args) throws Exception{ Property property1 = new Property(24,"Boston Australia",3,45,67); Property property2 = new Property(24,"Boston Malvern",3,45,67); Property property3 =

在这个程序中,我将属性存储到arraylist

public static void main(String [] args) throws Exception{
Property property1 = new Property(24,"Boston Australia",3,45,67);

        Property property2 = new Property(24,"Boston Malvern",3,45,67);
        Property property3 = new Property(24,"Boston Caulfield",3,45,67);
        Property property4 = new Property(24,"Boston Caulfield",3,45,67);
        Property property5 = new Property(24,"Boston Caulfield",3,45,67);
        SimplePropertyRepositoryImpl sl;
        sl = new SimplePropertyRepositoryImpl();
        sl.addProperty(property1);
        sl.addProperty(property2);
        sl.addProperty(property3);
        sl.addProperty(property4);
        sl.addProperty(property5);
}
public class SimplePropertyRepositoryImpl implements PropertyRepository{
    ArrayList<Property> properties;

    public SimplePropertyRepositoryImpl(){
        properties = new ArrayList<>();

    }
    @Override
    public void addProperty(Property property) throws Exception {

         properties.add(property);


        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }
SimplePropertyRepositoryImpl有一个addProperty方法,我在其中将property对象添加到arraylist

public static void main(String [] args) throws Exception{
Property property1 = new Property(24,"Boston Australia",3,45,67);

        Property property2 = new Property(24,"Boston Malvern",3,45,67);
        Property property3 = new Property(24,"Boston Caulfield",3,45,67);
        Property property4 = new Property(24,"Boston Caulfield",3,45,67);
        Property property5 = new Property(24,"Boston Caulfield",3,45,67);
        SimplePropertyRepositoryImpl sl;
        sl = new SimplePropertyRepositoryImpl();
        sl.addProperty(property1);
        sl.addProperty(property2);
        sl.addProperty(property3);
        sl.addProperty(property4);
        sl.addProperty(property5);
}
public class SimplePropertyRepositoryImpl implements PropertyRepository{
    ArrayList<Property> properties;

    public SimplePropertyRepositoryImpl(){
        properties = new ArrayList<>();

    }
    @Override
    public void addProperty(Property property) throws Exception {

         properties.add(property);


        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }

请帮助我理解,当我没有使用任何不可修改的集合时,为什么会出现此异常。

addProperty
中删除无条件的
抛出。大概

public void addProperty(Property property) throws Exception {
     properties.add(property);
     // throw new UnsupportedOperationException("Not supported yet.");
}

由于上述
抛出
未被注释掉,因此
抛出
UnsupportedOperationException
抛出新的UnsupportedOperationException(“尚不受支持”)-代码完全按照要求执行;异常跟踪准确地指出了它被写入的位置-
。在SimplePropertyRepositoryImpl.addProperty..(第29行)