Results 1 to 3 of 3
Thread: [Help ERROR] RPG 2D Map!
- 11-16-2011, 11:19 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
[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) { } }
- 11-17-2011, 01:42 AM #2
Member
- Join Date
- Jun 2011
- Posts
- 21
- Rep Power
- 0
Re: [Help ERROR] RPG 2D Map!
Please Link to here on status: [Help ERROR] RPG 2D Map!
- 11-17-2011, 01:44 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
java out of memory error-heap space error
By elsanthosh in forum NetBeansReplies: 4Last Post: 06-15-2010, 09:31 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM


LinkBack URL
About LinkBacks

Bookmarks