Results 1 to 3 of 3
  1. #1
    santafan is offline Member
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default [Help ERROR] RPG 2D Map!

    Okay so im trying to load a .txt to an array so it can be set a tiles. However on the loading im getting a "NullPointerException". Can someone point me into the right direction to where im going wrong? Possiably some source code please !

    Java Code:
    	private static final long serialVersionUID = 1L;
        public static Image GRASS;
        public static Image DIRT;
        
        private int x, y;
    	private static int xDirection;
    	private static int yDirection;
    	
    	static Rectangle[] blocks;
        static Image[] blockImg;
    	
    	private final int arrayNum = 523;
    	
        //Map navigation
        public static final int PAN_UP = 0, PAN_DOWN = 1, PAN_LEFT = 2, PAN_RIGHT = 3;
        
        public WorldMap() {
           
            ImageIcon g = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/Map/grass.png");
            ImageIcon d = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/Map/dirt.png");
    
            GRASS = g.getImage();
            DIRT = d.getImage();
            
            setSize(501, 419);
            
            blocks = new Rectangle[523];
            blockImg = new Image[523];
            
            loadMap();
           
        }
    
    	public void loadMap() {
    
            int x = 0;
            int y = 0;
            int j = 0;
            int loc = 0;
      
            try {
                File file = new File(System.getProperty("user.home") + "/Desktop/GAME/Map/map.txt");
                Scanner scan = new Scanner(file);
                for (String line = scan.nextLine(); line != null; line = scan.nextLine()) {
                    j = line.length() * 20;
                    while (j > x) {
                    	for(int i = 0; i < arrayNum; i++){
                    		char c = line.charAt(loc);
                    		if (c=='G') {
                    			blockImg[i] = GRASS;
                    			blocks[i] =  new Rectangle(x, y, 20, 20);
                    		}
                    		if (c=='D') {
                    			blockImg[i] = DIRT;
                    			blocks[i] =  new Rectangle(x, y, 20, 20);
                    		}
                    		x += 20;
                    		loc++;
                    	}
                    }
                    y += 20;
                    x = 0;
                    loc = 0;
                 }
            } catch (Exception e) {  
            }
        }

  2. #2
    santafan is offline Member
    Join Date
    Jun 2011
    Posts
    21
    Rep Power
    0

    Default Re: [Help ERROR] RPG 2D Map!

    Please Link to here on status: [Help ERROR] RPG 2D Map!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 10:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 05:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 09:53 AM

Posting Permissions

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