Bookmark this thread:  |
Login | |
|
RE: Any Java programmers? - Apr. 14 2008 22:24:58
| |
|
ZEn101
Posts: 579
Joined: Jun. 6 2006 Status: online
 |
public Ball(int x, int y) { posx = x; posy = y; System.out.println("posx= " + posx + "posy= " + posy); speed(); } public void draw(Graphics g, Main main) { // Testing //System.out.println("here!!2"); if(moving) { //speed(main); processWallCollision(); processBatCollision(main); processBlockCollision(main); processOffScreen(main); // Testing //System.out.println(xdistance); //System.out.println(ydistance); posx += (xdistance); posy += (ydistance); } // Testing // System.out.println(posy); // Draw ball g.setColor(Color.RED); g.fillOval(posx, posy, WIDTH, HEIGHT); } public void resetBall(Main main) { // Testing System.out.println("RESETTING BALL!"); ball = new Ball(355, 635); ball.draw(g, main); main.bat.resetBat(); } ERRORS Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Ball.draw(Ball.java:359) at Ball.resetBall(Ball.java:452) at Ball.processOffScreen(Ball.java:197) at Ball.draw(Ball.java:346) at Main$PlayPanel.paintComponent(Main.java:244) at javax.swing.JComponent.paint(JComponent.java:1027) at javax.swing.JComponent.paintChildren(JComponent.java:864) at javax.swing.JComponent.paint(JComponent.java:1036) at javax.swing.JComponent.paintChildren(JComponent.java:864) at javax.swing.JComponent.paint(JComponent.java:1036) at javax.swing.JLayeredPane.paint(JLayeredPane.java:564) at javax.swing.JComponent.paintChildren(JComponent.java:864) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5129) at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285) at javax.swing.RepaintManager.paint(RepaintManager.java:1128) at javax.swing.JComponent.paint(JComponent.java:1013) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
_____________________________
My journal Email me food
| |
|
RE: Any Java programmers? - Apr. 14 2008 22:26:33
| |
|
ZEn101
Posts: 579
Joined: Jun. 6 2006 Status: online
 |
The ball posx/y are reset properly, but the ball isn't redrawn as g seemingly is empty!?
_____________________________
My journal Email me food
| |
|
RE: Any Java programmers? - Apr. 15 2008 9:42:58
| |
|
Dan Nukem
Posts: 8889
Joined: Sep. 21 2002 From: Ireland Status: offline
 |
What change did you make to the original code in order to get it to work? (to satisfy my curiosity please) Going by memory here, but I think the items in your array aren't defined, therefore giving the null pointer exception. The compiler is aware there is an array, but its not aware thats its an array of balls. BTW, I always hated repaint, always found it a ballache
| |
|
RE: Any Java programmers? - Apr. 15 2008 15:21:12
| |
|
ZEn101
Posts: 579
Joined: Jun. 6 2006 Status: online
 |
I used the count instead of counting the OBJECTS which were blocks ... fking stupid really i had been programmnig for hours was getting dopy!! Fixed ball re-initialisation aswell all working just need to add a new level!
_____________________________
My journal Email me food
| |
|
|