Java Android Studio中没有类Def Found Error

时间:2015-12-24 00:06:16

标签: java android compiler-errors libgdx

我一直在开发Pacman克隆,我正在使用以下类生成迷宫:它在netbeans上运行良好但是当我尝试将其导入到Android工作室以便我可以将它与LibGDX一起使用时它会给我一些错误他们在这里:S:

FATAL EXCEPTION: GLThread 187
Process: com.fistbump.patman.android, PID: 2221
java.lang.NoClassDefFoundError: com.patman.mazegeneration.Maze2D$Node$2
at com.patman.mazegeneration.Maze2D$Node.getNeighbours(Maze2D.java:197)
at com.patman.mazegeneration.Maze2D$Node.linkRandomUnlinkedNeighbour(Maze2D.java:176)
at com.patman.mazegeneration.Maze2D$Maze.growMaze(Maze2D.java:125)
at com.patman.mazegeneration.Maze2D$Maze.<init>(Maze2D.java:95)
at com.patman.mazegeneration.Maze2D.<init>(Maze2D.java:33)
at com.fistbump.patman.MyGdxGame.create(MyGdxGame.java:25)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

,代码是:

package com.patman.mazegeneration;


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;


public class Maze2D {

private BufferedImage im;

public BufferedImage getIm() {
    return im;
}

public void setIm(BufferedImage im) {
    this.im = im;
}

public Maze2D(int x, int y) {

    new Maze(x, y);

}

public static final class Coordinate2D {
    private final Maze maze;
    private final int x, y;

    public Coordinate2D(Maze maze, int x, int y) {
        Objects.requireNonNull(maze);
        if (x < 0 || x >= maze.xSize || y < 0 || y >= maze.ySize)
            throw new IndexOutOfBoundsException();
        this.maze = maze;
        this.x = x;
        this.y = y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(maze, x, y);
    }

    @Override
    public boolean equals(Object another) {
        if (!(another instanceof Coordinate2D)) return false;
        Coordinate2D c4d = (Coordinate2D) another;
        return maze == c4d.maze && x == c4d.x && y == c4d.y;
    }


    public Coordinate2D minusX() {
        return x == 0 ? null : new Coordinate2D(maze, x - 1, y);
    }

    public Coordinate2D plusX() {
        return x == maze.xSize - 1 ? null : new Coordinate2D(maze, x + 1, y);
    }

    public Coordinate2D minusY() {
        return y == 0 ? null : new Coordinate2D(maze, x, y - 1);
    }

    public Coordinate2D plusY() {
        return y == maze.ySize - 1 ? null : new Coordinate2D(maze, x, y + 1);
    }

    public Maze getMaze() {
        return maze;
    }
}

public final class Maze {
    private final int xSize, ySize;
    private final Map<Coordinate2D, Node> nodes;
    private final Node start;

    public Maze(int x, int y) {
        this.xSize = x;
        this.ySize = y;
        nodes = new HashMap<>(x * y);
        fill();
        this.start = chooseRandomNode();
        growMaze();
        im = draw();
    }

    private void fill() {
        for (int b = 0; b < xSize; b++) {
            for (int c = 0; c < ySize; c++) {
                Coordinate2D coord = new Coordinate2D(this, b, c);
                nodes.put(coord, new Node(coord));
            }
        }
    }

    public Node nodeAt(Coordinate2D coord) {
        if (coord == null) return null;
        return nodes.get(coord);
    }

    private Node chooseRandomNode() {
        int n = (int) (Math.random() * xSize * ySize);
        return new ArrayList<>(nodes.values()).get(n);
    }

    private void growMaze() {
        List<Node> frontier = new ArrayList<>(xSize * ySize);
        frontier.add(start);
        start.linked = true;
        while (!frontier.isEmpty()) {
            Collections.shuffle(frontier);
            Node n = frontier.get(0);
            Node next = n.linkRandomUnlinkedNeighbour();
            if (next != null) {
                frontier.add(next);
            } else {
                frontier.remove(0);
            }
        }
    }

    public BufferedImage draw() {
        int cellWidth = 40;
        int cellHeight = 40;
        int boardWidth = cellWidth * (xSize + 1);
        int boardHeight = cellHeight * (ySize + 1);
        BufferedImage im = new BufferedImage(boardWidth + cellWidth, boardHeight + cellHeight, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = im.createGraphics();
        g.setPaint(new Color(255, 255, 255));
        g.fillRect(0, 0, im.getWidth(), im.getHeight());
        for (int x = 0; x < xSize; x++) {
            for (int y = 0; y < ySize; y++) {
                Coordinate2D c = new Coordinate2D(this, x, y);
                Node n = nodeAt(c);
                int x1 = cellWidth * x + cellWidth - 1;
                int y1 = cellHeight * y + cellHeight - 1;
                int x2 = x1 + cellWidth;
                int y2 = y1 + cellHeight;
                g.setColor(Color.BLACK);
                g.setStroke(new BasicStroke(20));
                if (!n.isLinkedTo(n.minusY())) g.drawLine(x1, y1, x2, y1);
                if (!n.isLinkedTo(n.plusY())) g.drawLine(x1, y2, x2, y2);
                if (!n.isLinkedTo(n.minusX())) g.drawLine(x1, y1, x1, y2);
                if (!n.isLinkedTo(n.plusX())) g.drawLine(x2, y1, x2, y2);
            }
        }
        return im;
    }
}

private class Node {
    private final Coordinate2D coord;
    private final List<Node> linkedNeighbours;
    private List<Node> neighbours;
    private boolean linked;

    public Node(Coordinate2D coord) {
        Objects.requireNonNull(coord);
        this.coord = coord;
        linkedNeighbours = new ArrayList<>(8);
    }

    public Node linkRandomUnlinkedNeighbour() {
        List<Node> list = new ArrayList<>(getNeighbours());
        list.removeIf(new Predicate<Node>() {
            @Override
            public boolean test(Node n) {
                return n.linked;
            }
        });
        if (list.isEmpty()) return null;
        Collections.shuffle(list);
        Node next = list.get(0);
        next.getNeighbours();
        linkedNeighbours.add(next);
        next.linkedNeighbours.add(this);
        next.linked = true;
        return next;
    }

    @SuppressWarnings("ReturnOfCollectionOrArrayField")
    public List<Node> getNeighbours() {
        if (neighbours == null) {
            List<Node> nodes = new ArrayList<>(Arrays.asList(minusX(), plusX(), minusY(), plusY()));
            nodes.removeIf(new Predicate<Node>() {
                @Override
                public boolean test(Node x) {
                    return x == null;
                }
            });
            neighbours = Collections.unmodifiableList(nodes);
        }
        return neighbours;
    }


    public boolean isLinkedTo(Node node) {
        return linkedNeighbours.contains(node);
    }

    public Maze getMaze() {
        return coord.getMaze();
    }

    public Node minusX() {
        return getMaze().nodeAt(coord.minusX());
    }

    public Node plusX() {
        return getMaze().nodeAt(coord.plusX());
    }

    public Node minusY() {
        return getMaze().nodeAt(coord.minusY());
    }

    public Node plusY() {
        return getMaze().nodeAt(coord.plusY());
    }
}

}

提前非常感谢

0 个答案:

没有答案