Results 1 to 7 of 7
- 02-13-2013, 07:08 PM #1
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
maze game error something about unkown source?
Hey im following a tutorial to get an idea on games in java and when i paint my map to the jframe it loops through the printing but prints this error message. im thinking the images are not initialized? but im sure they are
error message it repeats this till i close the JFrame
Java Code:at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at maze.Map.getMap(Map.java:50) at maze.Board.paintComponent(Board.java:43) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintToOffscreen(Unknown Source) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source) at javax.swing.RepaintManager$PaintManager.paint(Unknown Source) at javax.swing.RepaintManager.paint(Unknown Source) at javax.swing.JComponent._paintImmediately(Unknown Source) at javax.swing.JComponent.paintImmediately(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.access$700(Unknown Source) at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Java Code:package maze; import javax.swing.*; public class Maze { public static void main (String[] args) { new Maze(); } public Maze() { JFrame f= new JFrame(); f.setTitle("1st Maze game by CJE ver 1.0.0"); //sets frame title f.add(new Board()); //adds a game Board() f.setSize(1000, 800); f.setLocationRelativeTo(null); //sets location, relative refers to a component, but choose null, so it centers f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //closes jframe on exit and terminates jre } }Java Code:package maze; import java.awt.*; //graphics etc import java.awt.event.*; //action listeners etc import javax.swing.*; public class Board extends JPanel implements ActionListener{ private Timer timer; //used to time events private Map map; public Board() { map = new Map(); timer = new Timer(25, this); //25ms between actions every 25ms it will run action performed timer.start(); } /* * collections actions performed * */ public void actionPerformed(ActionEvent e){ // gets the actions performed repaint(); } /* * Graphics imported from awt.*; allows us to use super methods * Paint methods, allows us to draw stuff to JFrame * */ public void paintComponent(Graphics g) { super.paintComponent(g); //uses imported super class of Graphics for(int y = 0;y < 14; y ++){ //do rows first y = a row for(int x = 0; x < 14; x++){ // do tiles in row or x's if(map.getMap(x , y).equals("w")){ //will draw a water tile *32 because tile is 32x32 g.drawImage(map.getWater(), x * 32, y * 32, null); //null observer } if(map.getMap(x , y).equals("b")){ //will draw a buoy *32 because tile is 32*32 g.drawImage(map.getBuoy(), x * 32, y * 32, null); //null observer } } } } }Java Code:package maze; import java.util.*; import java.awt.Image; //for images import java.io.*; import javax.swing.*; // for imageIcon and icon stuff public class Map { private Scanner scan; private String Map[] = new String [16]; //16 refers to amount fo tiles going down, 16 tiles here private Image water, buoy; public Map() { //setting images ImageIcon img = new ImageIcon("/maze game/src/maze/maps/images/water.png"); water = img.getImage(); img = new ImageIcon("/maze game/src/maze/maps/images/buoy.png"); buoy = img.getImage(); //end of setting images loadMap(); //opens file } // gets for returning the image for board method calls public Image getWater() { return water; } public Image getBuoy() { return buoy; } //end gets /* * looks at map for x and y cords, * substring = is x position on y "row" * */ public String getMap(int x, int y){ String index = Map[y].substring(x ,x + 1); //if y = 2, looks in 2 row of map return index; } public void loadMap() { try { scan = new Scanner(new File("/maze game/src/maze/maps/map.txt")); while(scan.hasNext()){ //whilst map has a next element for(int i= 0; i <14; i++){ // Map[i] = scan.next(); //loads the found next element into the array i starts at 0, then 1 etc } } scan.close(); //SIMPLY CLOSES SCANNER } catch(IOException e){ System.err.print("error loading map"); } } }
- 02-13-2013, 07:12 PM #2
Re: maze game error something about unkown source?
Something is null. You're going to have to step through this with a debugger, or at least add some print statements, to figure out exactly what that is. What's going on in the line that throws the exception? What are you dereferencing? Where is it initialized? Something is null in that line.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-13-2013, 07:26 PM #3
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
Re: maze game error something about unkown source?
i was thinking of doing that, what is more likely to be null, one of the graphic elements? since they get " painted" into the Component?
line that throws the exception is
Java Code:public String getMap(intx, int y) { String index =Map[y].substring(x, x+1); return index; }
- 02-13-2013, 07:32 PM #4
Re: maze game error something about unkown source?
What index of Map (which should be map, by the way) are you trying to access when the error is thrown? What is stored at that index?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-13-2013, 07:49 PM #5
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
- 02-13-2013, 08:01 PM #6
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
Re: maze game error something about unkown source?
this works fine
but i dont thinkJava Code:public void loadMap() { try { scan = new Scanner(new File("/maze game/src/maze/maps/map.txt")); while(scan.hasNext()){ //whilst map has a next element for(int i= 0; i <14; i++){ // Map[i] = scan.next(); //loads the found next element into the array i starts at 0, then 1 etc } }
ORJava Code:public String getMap(int x, int y) { INT X AND Y ARE BOTH 0 IN THE DE BUGGER :/ THIS IS THE ISSUE String index =Map[y].substring(x, x+1); return index;
are working hmmmm...Java Code:public void paint(Graphics g) { super.paintComponent(g); //uses imported super class of Graphics for(int y = 0;y < 14; y ++){ //do rows first y = a row for(int x = 0; x < 14; x++){ // do tiles in row or x's if(map.getMap(x , y).equals("w")){ //will draw a water tile *32 because tile is 32x32 g.drawImage(map.getWater(), x * 32, y * 32, null); //null observer } if(map.getMap(x , y).equals("b")){ //will draw a buoy *32 because tile is 32*32 g.drawImage(map.getBuoy(), x * 32, y * 32, null); //null observer } } } }Last edited by monkeyjr97; 02-13-2013 at 08:06 PM.
- 02-13-2013, 08:49 PM #7
Senior Member
- Join Date
- Nov 2012
- Posts
- 223
- Rep Power
- 1
Similar Threads
-
Maze Solver Error in Getting instance variable
By jijiaremere in forum JCreatorReplies: 3Last Post: 02-04-2013, 10:41 AM -
Source Not Found compiling error
By bradjohns94 in forum New To JavaReplies: 5Last Post: 09-03-2012, 12:08 AM -
Source not found error even after including it
By nehatomar in forum EclipseReplies: 0Last Post: 06-03-2012, 11:10 PM -
Source tree shows error when there is none
By madroadbiker in forum NetBeansReplies: 0Last Post: 05-10-2011, 01:29 PM -
Can run, but unable to debug. Having 'Source not found' error.
By ko_aung in forum EclipseReplies: 4Last Post: 04-23-2010, 05:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks