0

Get the following when I use addToRegion for the paddle, when breakout is executed. No other changes made, just trying to create the initial paddle. Does anyone know how to fix?

jharvard@appliance (~/Dropbox/pset3/breakout): make breakout

clang -ggdb3 -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o breakout breakout.c -lcs -lm

jharvard@appliance (~/Dropbox/pset3/breakout): ./breakout

java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1086) at java.awt.Container.add(Container.java:410) at stanford.spl.JBEWindow.addToRegion(JBEWindow.java:101) at stanford.spl.GWindow_addToRegion.execute(JBECommand.java:226) at stanford.spl.JavaBackEnd.commandLoop(JavaBackEnd.java:625) at stanford.spl.JavaBackEnd.run(JavaBackEnd.java:164) at stanford.spl.JavaBackEnd.main(JavaBackEnd.java:136) Unexpected error: null

^C

jharvard@appliance (~/Dropbox/pset3/breakout):

Code that has been changed below:

GRect initPaddle(GWindow window)

{

GRect paddle = newGRect(0, 0, pWIDTH, pHEIGHT);

  setFilled(paddle, true);
  setColor(paddle, "BLACK");

  double x = (getWidth(window) - getWidth(paddle)) / 2;
  double y = (getHeight(window) - getHeight(paddle)) / 2;
  setLocation(paddle, x, y);
  addToRegion(window, paddle, "SOUTH");
  return paddle;

  closeGWindow(window);
  return 0;

}

I also added the following further up with the rest of the definitions:

// height and width of game's paddle in pixels

"#define pHEIGHT 50"

"#define pWIDTH 100"

  • wanna show us some code? – Kareem Oct 17 '15 at 16:44
  • Apologies! will add – Steve23455 Oct 17 '15 at 17:01
  • The program executes, but it doesn't show the paddle when I use addToRegion, it just shows the window. If i just use add(window, paddle) it will show in the center of the window with no errors. Still need to get it into the South region somehow. – Steve23455 Oct 18 '15 at 10:56
  • You don't need to use addToRegion, when you use add(window, paddle), it adds the paddle to the x and y coordinates you specified in creating it with newGRect(x, y, width, height). You can just specify a different Y position in newGRect(x, y, width, height), or you can create it in the center of the window like you are already doing and use setLocation(paddle, x, y) to place it wherever you want. – Marti Serra Oct 28 '15 at 11:00

You must log in to answer this question.

Browse other questions tagged .