Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.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 获取错误:范围内无法访问Polyline类型的封闭实例_Java - Fatal编程技术网

Java 获取错误:范围内无法访问Polyline类型的封闭实例

Java 获取错误:范围内无法访问Polyline类型的封闭实例,java,Java,这里我为我的对象多段线创建了一个多段线迭代器。下面是迭代器的代码 public class PolyLineIterator { private int current = -1; public PolyLineIterator() { if(Polyline.this.vertices.length > 0 ) { current = 0; } } public boolean hasVertex() {

这里我为我的对象多段线创建了一个多段线迭代器。下面是迭代器的代码

 public class PolyLineIterator {
   private int  current = -1;
   public PolyLineIterator() {
       if(Polyline.this.vertices.length > 0 ) {
           current = 0;
       }
   }
   public boolean hasVertex() {
       return current != -1;
   }
   public  Point vertex() throws java.util.NoSuchElementException {
       if(!this.hasVertex())throw  new  java.util.NoSuchElementException("end of iteration");
       Point vertex = Polyline.this.vertices[current];
       return vertex;
   }
   public void advance() {
       if(current >= 0 && current < Polyline.this.vertices.length - 1) {
           current ++;
       }else {
           current = -1;
       }
   }

}
公共类多段线迭代器{
私有整数电流=-1;
公共多段线迭代器(){
如果(Polyline.this.vertices.length>0){
电流=0;
}
}
公共布尔顶点(){
返回电流!=-1;
}
public Point vertex()抛出java.util.NoSuchElementException{
如果(!this.hasVertex())抛出新的java.util.NoSuchElementException(“迭代结束”);
点顶点=多段线。此。顶点[当前];
返回顶点;
}
预支{
if(当前>=0&¤t
当我输入完代码后,在多段线下面会弹出一个错误,并显示以下内容:-

在范围中无法访问Polyline类型的封闭实例


如何解决此问题?

您的类不是多段线中的嵌套类。
PolyLineIterator
Polyline
之间的关系是什么?为什么要使用
多段线。这个.vertices
构造?我必须在测试程序中为类Polyline创建一个PolyLineIterator实例,我必须按顺序访问每个顶点并打印它们。似乎你从某个地方复制并粘贴了这段代码,而没有理解
多段线。这个
只能是如果迭代器是多段线的内部类,则使用。我是根据一项作业发布代码的。