Ich habe drei Klassen: Mazesolver
, Hexagon
und Maze
. Wenn ich versuche, ein Hexagon
Objekt in der Mazesolver
Klasse zu erstellen, tritt ein Fehler auf. Kann mir bitte jemand bei diesem Problem helfen? Was bedeutet es auch, einen Hinweis auf den Start Hexagon
im Labyrinth zu erhalten?Wie erstelle ich ein Objekt in einer anderen Klasse, wenn der Parameter außerhalb des Gültigkeitsbereichs liegt?
public class Hexagon extends HexComponent
{
// constants
private static final Color WALL_COLOR = Color.BLACK;
private static final Color START_COLOR = Color.GREEN;
private static final Color END_COLOR = Color.YELLOW;
private static final Color UNVISITED_COLOR = Color.CYAN;
private static final Color PROCESSED_COLOR = Color.BLUE;
private static final Color PUSHED_COLOR = Color.MAGENTA;
private static final Color END_PROCESSED_COLOR = Color.RED;
private static final Color START_PROCESSED_COLOR = Color.PINK;
//enum to represent available hexagon types
public static enum HexType{WALL, START, END, UNVISITED, PROCESSED, PUSHED, END_PROCESSED, START_PROCESSED};
// Attributes
private HexType type; // Stores the type of Hexagon this currently is
private boolean isStart; // Is this the start?
private boolean isEnd; // Is this the end?
private Hexagon[] neighbors; // Stores the hexagons which surround this one on each of 6 sides
/**
* Create a Hexagon tile of the specified type
* @param t the HexType to create
*/
public Hexagon(HexType t) {
this.type = t;
this.isStart = t == HexType.START;
this.isEnd = t == HexType.END;
//set the initial color based on the initial type
this.setColor(this.type);
//allocate space for the neighbor array
this.neighbors = new Hexagon[6];
}
Wie erstelle ich ein Objekt von Hexagon in MazeSolver?
public class MazeSolver
{
public static void main (String[] args) {
try {
if (args.length < 1) {
throw new IllegalArgumentException("No Maze Provided");
}
String maze0 = args[0];
private ArrayStack<String> steps;
Hexagon Start = new Hexagon(t); //error
}
Ihre 'ArrayStack' -Instanz' steps' hat einen unzulässigen Modifikator. Sie können 'private' nicht für eine lokal begrenzte Variable innerhalb einer Methode verwenden. Darüber hinaus haben Sie keine Details zu der Art des angezeigten Fehlers angegeben. Bitte fügen Sie diese Informationen Ihrem Beitrag hinzu. Wie auch immer, es ist unmöglich zu sagen, welche Fehler auf ein fehlerhaftes Kopieren/Einfügen zurückzuführen sind. – nbrooks