This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tomc84
Tomc84 wrote ...

2012/3/1

error

Tomc84 Tomc84

2012/3/1

#
Iam getting an error that I cant fix... java.lang.NullPointerException at PongWorld.updateScore(PongWorld.java:49) at Ball.ballMove(Ball.java:54) at Ball.act(Ball.java:39) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) ...... I have this in the world... public PongWorld() { // Create a new world with 700x500 cells with a cell size of 1x1 pixels. super(700, 500, 1); p1 = new Paddle("a", "s", "John"); // added arguments key control // step 1 and 2 addObject(p1, 350, 30); p2 = new Paddle("left", "right", "Joe"); addObject(p2, 350, 470); ball = new Ball(); addObject(ball, 350, 250); Label Txt1= new Label(p1.getName()+ ": " + p1.getScore() ); // add text to world + score count addObject(Txt1, 72, 59); Label Txt2 = new Label(p2.getName()+ ": " + p2.getScore() ); // get name and score from paddle getter and setter method addObject(Txt2, 72, 453); } /** * update paddle scores from paddle methods (getter / setter) getScore setScore */ public void updateScore(Ball ball) { if (ball.getY() == 0) // noth paddle score { p2.setScore(p2.getScore() +1); // updateScore (getScore add 1) Txt2.setText(p2.getName() + ": " + p2.getScore()); } if (ball.getY() == 500-1) // south paddle score lagest y is 499(500-1) world 0-499 on Y { p1.setScore(p1.getScore() +1); Txt1.setText(p1.getName() + ": " + p1.getScore()); } .... this in my ball public void ballMove() // NEW MOVE METHOD for setting the ball in center of screen { if (getY() == 0 || getY() == 500-1) { ((PongWorld)getWorld()).updateScore(this); setLocation( 350, 250 ); // ball set or reset wait = 80; // added wait for reset ball position ySpeed = Greenfoot.getRandomNumber(3)+1; if (Greenfoot.getRandomNumber(2)==0) // Y up or down 50/50 chance (0-1) if 0 do this { ySpeed = ySpeed *(-1); // chance to be negative or positive } xSpeed = Greenfoot.getRandomNumber(3)+1; if (Greenfoot.getRandomNumber(2)==0) // X right or left 50/50 chance { xSpeed = xSpeed *(-1); } } else { setLocation(getX() +xSpeed,getY() +ySpeed); //movement and speed bounceOffPaddle(); // new call for bounceOffPaddle } ... can anyone help me?
Tomc84 Tomc84

2012/3/1

#
never mind this post I found my problem
You need to login to post a reply.