Jhurd23
YaBB Newbies
Offline
Posts: 8
Re: Null Pointer Exception Map Project(Please Help
Reply #2 - Feb 21st , 2008, 5:52pm
ok, i revised my code as you suggested, and I'm still getting a nullpointer exception. java.lang.NullPointerException at Temporary_5190_502$Map.create(Temporary_5190_502.java:86) at Temporary_5190_502.draw(Temporary_5190_502.java:14) at processing.core.PApplet.handleDisplay(PApplet.java:1465) at processing.core.PGraphics.requestDisplay(PGraphics.java:690) at processing.core.PApplet.run(PApplet.java:1562) at java.lang.Thread.run(Unknown Source) java.lang.NullPointerException at Temporary_5190_502$Map.create(Temporary_5190_502.java:86) at Temporary_5190_502.draw(Temporary_5190_502.java:14) at processing.core.PApplet.handleDisplay(PApplet.java:1465) at processing.core.PGraphics.requestDisplay(PGraphics.java:690) at processing.core.PApplet.run(PApplet.java:1562) at java.lang.Thread.run(Unknown Source) There's the exception, and map1.txt is as follows: grass grass Here's my revised code:int tileSize = 20; Tile grass = new Tile(color(0, 200, 0), tileSize, tileSize); Map map1 = new Map(tileSize, tileSize, 10, 10, "map1"); void setup(){ size(800, 500); } void draw(){ background(0); grass.create(0, 0); map1.update(); map1.create(); PFont fontA = loadFont("CourierNew36.vlw"); textFont(fontA, 36); text(map1.returnMapTilesLength(), width/2, height/2); } class Tile{ String name; float h; float w; color base; Tile(color dbase, float dh, float dw){ base = dbase; h = dh; w = dw; } void create(float dx, float dy){ fill(base); rect(dx, dy, w, h); } void identify(String dname){ name = dname; } } class Map{ String name; float tileW; float tileH; int mapW; int mapH; float w = tileW * mapW; float h = tileH * mapH; Tile[] MapTiles = new Tile[0]; String[] MapLoad; String[] MapSave = new String[MapTiles.length]; Map(float dtileW, float dtileH, int dmapW, int dmapH, String dname){ tileW = dtileW; tileH = dtileH; mapH = dmapH; mapW = dmapW; name = dname; } void update(){ for(int i = 0; i < MapTiles.length; i++){ MapTiles[i] = new Tile(color(0, 200, 0), tileSize, tileSize); } MapTiles = (Tile[])expand(MapTiles, mapW * mapH); MapSave = (String[])expand(MapSave, mapW * mapH); for(int i = 0; i < MapTiles.length; i++){ MapSave[i] = "grass"; } //saveStrings( name + ".txt", MapSave); MapLoad = loadStrings(name + ".txt"); for(int i = 0; i < MapTiles.length; i++){ if(i <= MapLoad.length-1){ if(MapLoad[i].equals("grass")){ MapTiles[i] = new Tile(color(0, 200, 0), tileSize, tileSize); } } } } void create(){ for(int i = 0; i < MapLoad.length; i++){ MapTiles[i].identify(MapLoad[i]); } for(int i = 0; i < MapTiles.length; i++){ MapTiles[i].create(i*tileSize, i*tileSize); } } int returnMapTilesLength(){ return MapTiles.length; } int returnMapLoadLength(){ return MapLoad.length; } int returnmapH(){ return mapH; } int returnmapW(){ return mapW; } } Thank you for the help!