Java Can';“找不到”;令牌语法错误,请删除这些令牌“;

Java Can';“找不到”;令牌语法错误,请删除这些令牌“;,java,processing,Java,Processing,我正在为一个使用处理的项目编写Dijkstra算法的实现,我不断得到错误“令牌上的语法错误,删除这些令牌”,没有任何关于错误在哪个文件中的指示,或者错误在文件中的位置,我一辈子都找不到问题在哪里 任何帮助都将不胜感激 LargeGraph.pde: ArrayList<Vertex> vertices; ArrayList<Edge> edges; void setup() { size(1000, 1000); vertices = new ArrayList

我正在为一个使用处理的项目编写Dijkstra算法的实现,我不断得到错误“令牌上的语法错误,删除这些令牌”,没有任何关于错误在哪个文件中的指示,或者错误在文件中的位置,我一辈子都找不到问题在哪里

任何帮助都将不胜感激

LargeGraph.pde:

ArrayList<Vertex> vertices;
ArrayList<Edge> edges;

void setup() {
  size(1000, 1000);
  vertices = new ArrayList<Vertex>();
  edges = new ArrayList<Edge>();
  randomSeed(22);
  fillVertices();
  fillEdges();
}

void draw() {
  background(0);
  stroke(255);

  for (Vertex v : vertices) {
    if (vertices.indexOf(v) == 7) {
      fill(255, 0, 0);  
    }
    circle((v.x + 1) * 19, (v.y + 1) * 19, 10);
    fill(255);
  }

  for (Edge e : edges) {
    line((e.v1.x + 1) * 19, (e.v1.y + 1) * 19, (e.v2.x + 1) * 19, (e.v2.y + 1) * 19); 
  }

  calculateSPT(vertices.get(0));
  println(getShortestPathTo(vertices.get(7)));
}

class Vertex implements Comparable<Vertex> {
  int x, y, id, csf;
  double minDistance;
  Vertex previous;

  Vertex (int num, int xpos, int ypos) {
    minDistance = 999999999999999999999999999999.;
    id = num;
    x = xpos;
    y = ypos;
    csf = 0;
  }

  ArrayList<Edge> adjacencies() {
    ArrayList<Edge> adjacencies = new ArrayList<Edge>();

    for (Edge e : edges) {
      if (e.v1.equals(this)) {
        adjacencies.add(e);  
      }
    }

    return adjacencies;
  }

  @Override
  public int compareTo(Vertex other) {
    if (this.csf > other.csf) {
      return 1;  
    } else if (this.csf == other.csf) {
      return 0;
    } else {
      return -1;
    }
  }
}

class Edge {
  Vertex v1;
  Vertex v2;
  int weight;

  Edge(Vertex v, Vertex v0, int w) {
    v1 = v;
    v2 = v0;
    weight = w;
  }
}

void fillEdges() {
  // for each vertex pick a random number 2-5 and generate an edge
  // to a random vertex with a weight based on its distance in space
  // times a random factor

  for (Vertex v : vertices) {
    int numEdges = 1; //round(random(2, 5));
    //for (int i = 0; i < numEdges; i++) {
      Vertex vertex = vertices.get(round(random(0, 9)));
      if (vertex.equals(v)) {
        vertex = vertices.get(round(random(0, 9)));
      }
      int weight = int(dist(v.x, v.y, vertex.x, vertex.y) * random(0, 2));

      edges.add(new Edge(v, vertex, weight));
    //}
  }
}

void fillVertices() {
  for (int i = 0; i < 10; i++) {
    int x = round(random(0, 50));
    int y = round(random(0, 50));

    vertices.add(new Vertex(i, x, y));
  }
}
ArrayList顶点;
阵列列表边;
无效设置(){
大小(10001000);
顶点=新的ArrayList();
边=新的ArrayList();
随机种子(22);
填充顶点();
填充边();
}
作废提款(){
背景(0);
中风(255);
对于(顶点v:顶点){
if(顶点索引of(v)==7){
填充(255,0,0);
}
圆圈((v.x+1)*19,(v.y+1)*19,10);
填充(255);
}
用于(边e:边){
行((e.v1.x+1)*19,(e.v1.y+1)*19,(e.v2.x+1)*19,(e.v2.y+1)*19);
}
calculateSPT(顶点.get(0));
println(getShortestPathTo(顶点.get(7));
}
类Vertex实现了可比较的{
intx,y,id,csf;
双重心态;
顶点前向;
顶点(int num、int xpos、int ypos){
minDistance=99999999999999999999999999。;
id=num;
x=xpo;
y=YPO;
csf=0;
}
ArrayList邻接(){
ArrayList邻接=新ArrayList();
用于(边e:边){
如果(e.v1等于(本)){
增加(e);
}
}
返回邻接;
}
@凌驾
公共整数比较(顶点其他){
如果(this.csf>other.csf){
返回1;
}else if(this.csf==other.csf){
返回0;
}否则{
返回-1;
}
}
}
阶级边缘{
顶点v1;
顶点v2;
整数权重;
边(顶点v、顶点v0、整数w){
v1=v;
v2=v0;
重量=w;
}
}
void fillEdges(){
//对于每个顶点,选择一个随机数2-5并生成一条边
//到随机顶点,其权重基于其在空间中的距离
//乘以一个随机因子
对于(顶点v:顶点){
int numEdges=1;//四舍五入(随机(2,5));
//for(int i=0;i
Dijkstra.pde:

import java.util.Collections;
import java.util.PriorityQueue<E>;

void calculateSPT(Vertex start) {  
  start.minDistance = 0.;
  PriorityQueue<Vertex> vertexQueue = new PriorityQueue<Vertex>();
  vertexQueue.add(start);

  while (!vertexQueue.isEmpty()) {
    Vertex u = vertexQueue.poll();

    for (Edge e : u.adjacencies()) {
      Vertex v = e.v2;
      int weight = e.weight;
      double costSoFar = u.minDistance + weight;
      if (costSoFar < v.minDistance) {
        vertexQueue.remove(v);

        v.minDistance = costSoFar;
        v.previous = u;
        vertexQueue.add(v);
      }
    }
  }
}

ArrayList<Vertex> getShortestPathTo(Vertex target) {
  ArrayList<Vertex> path = new ArrayList<Vertex>();
  for (Vertex v = target; v != null; v = v.previous) {
    path.add(v);  
  }

  Collections.reverse(path);
  return path;
}
import java.util.Collections;
导入java.util.PriorityQueue;
void calculateSPT(顶点开始){
start.minDistance=0。;
PriorityQueue vertexQueue=新建PriorityQueue();
添加(开始);
而(!vertexQueue.isEmpty()){
Vertex u=vertexQueue.poll();
对于(边e:u.邻接()){
顶点v=e.v2;
int-weight=e.weight;
双倍成本=单位距离+重量;
if(成本小于v.minDistance){
移除(v);
v、 minDistance=costSoFar;
v、 先前=u;
vertexQueue.add(v);
}
}
}
}
ArrayList getShortestPathTo(顶点目标){
ArrayList路径=新建ArrayList();
对于(顶点v=目标;v!=null;v=v.previous){
路径。添加(v);
}
集合。反向(路径);
返回路径;
}

我明白了-问题出在Dijkstra.pde的第2行。导入应该是
java.util.PriorityQueue
,而不是
java.util.PriorityQueue

这是一大堆需要我们为您调试的代码。为什么不试着从a开始,只添加代码,直到看到错误?那会告诉你是什么引起的。