1

I am following this chess tutorial and I am trying to add Guava 23.0 jar in my project in Eclipse 4.8.0. (As requested in the tutorial)

However I am encountering an import cannot be resolved error after adding the Guava jar file downloaded from: https://github.com/google/guava/wiki/Release23

The error is in the line:

import com.google.common.collect.ImmutableMap;

I have tried the two top voted answers from here but still encountering the same issue.

Am I missing a step or added the Guava jar file incorrectly? Someone kindly enlighten me on this.

package com.chess.engine.board;

import java.util.HashMap;
import java.util.Map;

import com.chess.engine.pieces.Piece;
import com.google.common.collect.ImmutableMap; //error underline at com.google

public abstract class Tile {

    protected final int tileCoordinate;

    private static final Map<Integer, EmptyTile> EMPTY_TILES = createAllPossibleEmptyTiles();

    private static Map<Integer, EmptyTile> createAllPossibleEmptyTiles() {

        final Map<Integer, EmptyTile> emptyTileMap = new HashMap<>();

        for(int i = 0; i < 64; i++) {
            emptyTileMap.put(i,  new EmptyTile(i));
        }

        return ImmutableMap.copyOf(emptyTileMap);
    }

    Tile(int tileCoordinate){
        this.tileCoordinate = tileCoordinate;
    }

    public abstract boolean isTileOccupied();

    public abstract Piece getPiece();

    public static final class EmptyTile extends Tile{

        EmptyTile(int coordinate){
            super(coordinate);
        }

        @Override
        public boolean isTileOccupied() {
            return false;
        }

        @Override
        public Piece getPiece() {
            return null;
        }
    }

    public static final class OccupiedTile extends Tile{

        private final Piece pieceOnTile;

        OccupiedTile(int tileCoordinate, Piece pieceOnTile){
            super(tileCoordinate);
            this.pieceOnTile = pieceOnTile;
        }

        @Override
        public boolean isTileOccupied() {
            return true;
        }

        @Override
        public Piece getPiece() {
            return this.pieceOnTile;
        }
    }
}
Timisorean
  • 1,388
  • 7
  • 20
  • 30
  • If you have a `module-info.java` in the default package, delete this file. Otherwise, add a screenshot of _Project > Properties: Java Build Path_, tab _Libraries_ to your question. – howlger Jan 27 '19 at 22:43
  • @howlger I deleted the `module-info.java` and the error is resolved. Thank you so much. – user2025110 Jan 28 '19 at 16:13

1 Answers1

1

Solution provided by @howlger in the comment above. I removed the module-info.java in the default package which resolved the error.