I’ve got two compile errors in one of my classes and I don’t understand why they’re there.
The top error is saying there needs to be another semi-colon and the bottom one says it needs another closing brace.
The bottom error disappears if i put in another curly brace but the top one doesn’t. Any ideas?
(This is probably a case of me being blind/stupid so i apologise in advance 🙂
package com.pathfinding;
import java.util.ArrayList;
public class EdgeNodeFactory
{
static boolean[][] edgeMatrix = new boolean[100][100];
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
edgeMatrix[i][j] = false;
}
}
static ArrayList<Node> nodes = new ArrayList<Node>();
static ArrayList<Edge> edges = new ArrayList<Edge>();
static int edgeCount = 0;
static int nodeCount = -1;
}

You’ve tried to put code (the
forloop) directly in your class – it’s not in a constructor, a method, or a static/instance initializer. That’s not valid. When do you want that code to be executed?I suspect your code should really look like this:
Note how I’ve made all the fields private and non-static… you should almost certainly be creating an instance of
EdgeNodeFactoryrather than using static fields, and you should almost always make fields private.