Results 1 to 2 of 2
  1. #1
    Samirjthe2nd is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default help with gridworld?

    I'm trying to make a "Pawn" in gridworld ... i have some ways to go but for now I just want it to show up on the grid... whenever i run the file it says

    C:\Users\Samir\javaprograms\chess\ 13: cannot access Pawn
    bad class file: C:\Users\Samir\javaprograms\chess\
    file does not contain class Pawn
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    world.add(new Location(1, 1), new Pawn());

    the code for the Pawn is this:
    Java Code:
    import info.gridworld.grid.Location;
    import java.util.ArrayList;
    import info.gridworld.grid.Grid;
    import java.awt.Color;
    public class Pawn extends Critter
    	public Grid<Pawn> grid;
        public Location location;
        public int direction;
        public Color color;
    	public Pawn()
    		color = Color.WHITE;
    		direction = Location.NORTH;
    		grid = null;
            location = null;
    	 public void act()
            if (getGrid() == null)
            ArrayList<Actor> actors = getActors();
            ArrayList<Location> moveLocs = getMoveLocations();
            Location loc = selectMoveLocation(moveLocs);
     public ArrayList<Location> getMoveLocations()
        	ArrayList<Location> locs = new ArrayList();
            return locs;
        public Location selectMoveLocation(ArrayList<Location> locs)
            int n = locs.size();
            if (n == 0)
                return getLocation();
            for(Location a: locs)
          		if ((a.compareTo(getLocation())<2))
          			return a;
          		return getLocation();
        public void makeMove(Location loc)
            if (loc == null)
    Idk if this matters or not... but java is not making a .class for this prog whenever i run it for some reason... help please.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    You declare Pawn to be part of the package. But you the have the source file in C:\Users\Samir\javaprograms\chess\ next to The two things - package and directory location - have to match.

    Put at the same place as (next to and see what happens, and make the package declarations the same for both classes. If you continue to hit problems describe the exact layout of the files involved in this program. And the commands you are using to compile and run the program.

Similar Threads

  1. Object Construction ends Program in GridWorld
    By BJ1110 in forum Advanced Java
    Replies: 9
    Last Post: 02-04-2011, 05:02 PM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. Need gridworld help
    By robertbob in forum New To Java
    Replies: 2
    Last Post: 05-03-2010, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts