线程“AWT-EventQueue-0”java.lang.IllegalAccessError中的异常

时间:2013-12-09 02:06:05

标签: java user-interface rmi

我有一个小游戏项目,我必须使用RMI创建一个多人游戏。我收到以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried to
access class PlayArea from class com.sun.proxy.$Proxy1
    at com.sun.proxy.$Proxy1.getPlayArea(Unknown Source)
    at GameClient.getPlayArea(GameClient.java:100)
    at PlayBoard.paintComponent(GUI.java:264)

现在这些参考文献如下: GameClient.java的一部分

public PlayArea getPlayArea() {
    PlayArea result = null;

    try {
        result = myServer.getPlayArea(clientID); // line 100 of GameClient.java
    } catch (Exception e) {
        System.out.println("Error: " + e);
        System.exit(1);
    }

    return result;
}

这是GUI.java的一部分

public void paintComponent(Graphics g) {
    PlayArea playArea = gui.getGameEngine().getPlayArea(); // line 264 of GUI.java

    super.paintComponent(g);

    LinkedList bricks = new LinkedList();

    int pixCoeff = brickSize - 1;
    for (int y = 0; y < bricksPerSide; y++) {
        int pixY = y * pixCoeff;
        for (int x = 0; x < bricksPerSide; x++) {

            int brick = playArea.getBrick(x, y);
            if (Colour.isBase(brick))
                continue;
            if (gui.displayMode == GUI.NOMARKED && Colour.isMarked(brick)) {
                continue;
            }

            int pixX = x * pixCoeff;
            bricks.add(new BoardBrick(pixX, pixY,
                    gui.displayMode == GUI.MARKEDASORIGINAL ? ColourMapper
                            .map(Colour.original(brick)) : (Colour
                            .isMarked(brick) ? Color.WHITE : ColourMapper
                            .map(brick))));
        }
    }

    g.setColor(ColourMapper.map(Colour.BASE));
    g.fillRect(0, 0, (brickSize - 1) * bricksPerSide + 1, (brickSize - 1)
            * bricksPerSide + 1);
    while (bricks.size() > 0) {
        BoardBrick brick = (BoardBrick) (bricks.removeFirst());
        brick.drawBrick(g);
    }

    if (gui.getGameEngine().isGameOver())
        gameOver(g);

}

这是PlayArea.java

import java.util.Random;

class PlayArea implements java.io.Serializable {
    public static final int NORTHSIDE = 0;

    public static final int SOUTHSIDE = 1;

    public static final int EASTSIDE = 2;

    public static final int WESTSIDE = 3;

    private int[][] grid;

    public PlayArea(int size) {
        grid = new int[size][size];
    }

    public static int randomSide(Random rng) {
        return rng.nextInt(4);
    }

    public int getSize() {
        return grid.length;
    }

    public int getBrick(int x, int y) {
        return grid[x][y];
    }

    public int getBrick(Coord c) {
        return getBrick(c.getX(), c.getY());
    }

    public void setBrick(int x, int y, int val) {
        grid[x][y] = val;
    }

    public void setBrick(Coord c, int val) {
        setBrick(c.getX(), c.getY(), val);
    }

    // --> play_area_init_collision_flipDraw
    public void init() {
        int size = getSize();
        for (int x = 0; x < size; x++)
            for (int y = 0; y < size; y++)
                if (x == 0 || y == 0 || x == size - 1 || y == size - 1)
                    setBrick(x, y, Colour.WALL);
                else
                    setBrick(x, y, Colour.BASE);
        setBrick(size / 2, size / 2, Colour.WALL);
        setBrick(size / 2 - 2, size / 2 - 2, Colour.WALL);
        setBrick(size / 2 - 2, size / 2 + 2, Colour.WALL);
        setBrick(size / 2 + 2, size / 2 - 2, Colour.WALL);
        setBrick(size / 2 + 2, size / 2 + 2, Colour.WALL);
    }

    public boolean collision(PlayingBlock block) {
        int topLeftX = block.getPosition().getX();
        int topLeftY = block.getPosition().getY();

        int height = block.getHeight();
        int length = block.getLength();
        for (int x = 0; x < length; x++)
            for (int y = 0; y < height; y++)
                if (!Colour.isBase(getBrick(topLeftX + x, topLeftY + y)))
                    return true;
        return false;
    }

    public void flipDraw(PlayingBlock block) {
        int topLeftX = block.getPosition().getX();
        int topLeftY = block.getPosition().getY();

        int height = block.getHeight();
        int length = block.getLength();
        for (int x = 0; x < length; x++)
            for (int y = 0; y < height; y++)
                setBrick(topLeftX + x, topLeftY + y, getBrick(topLeftX + x,
                        topLeftY + y)
                        ^ block.getColour());
    }

    // --<
    // --> play_area_getSquareColour_mark
    public int getSquareColour(int topLeftX, int topLeftY, int size) {
        // return 0 if no square found
        // square colour otherwise
        if (topLeftX + size > getSize() || topLeftY + size > getSize())
            return 0;
        int colour = getBrick(topLeftX, topLeftY);
        if (!Colour.isPlayBrick(colour))
            return 0;
        for (int x = topLeftX; x < topLeftX + size; x++)
            for (int y = topLeftY; y < topLeftY + size; y++)
                if (!Colour.isSameColour(colour, getBrick(x, y)))
                    return 0;
        return colour;
    }

    public void mark(int topLeftX, int topLeftY, int size) {
        for (int x = topLeftX; x < topLeftX + size; x++)
            for (int y = topLeftY; y < topLeftY + size; y++)
                setBrick(x, y, Colour.mark(getBrick(x, y)));
    }
    // --<
}

现在,奇怪的是,这在Windows中使用Java 1.6运行,但在OS X上它没有,我现在无法访问Windows机器。我在OS X 10.9上使用1.6.0_65。

我在网上发现了许多关于AWT-EventQueue-0的错误,但其中大多数错误都是NullPointerException,而不是IllegalAccessError。我很感激任何帮助,我对Java很新。

更新:代码绝对适用于1.5和1.6。这很可能与包含的库有关。我会继续相应地查看和编辑这篇文章。

0 个答案:

没有答案