Question about S4P Sprites

Hi. Two questions about using S4P Sprites library

  1. I cant make Sprite.addEventHandler() work. I am getting an Null pointer exception when I press the sprite button. I am aware there is an alternative method but I like the encapsulation offered by this approach.
    java.lang.NullPointerException
    at sprites.SMessenger.eventHandlerFailed(Unknown Source)
    at sprites.SMessenger.message(Unknown Source)
    at sprites.Sprite.fireEvent(Unknown Source)
    at sprites.Sprite.mouseEvent(Unknown Source)

  2. The reason the question is so vague is the exception stack trace is missing line numbers. Is it possible to rebuild the library and run with the modified version? Is there a folder in Processing that I will place the compiled class hierarchy?

Thanks Mike

It appears that you have managed to successfully added an event handler to the sprite. :relaxed:

In the console pane did you see this text just above the stack trace?
############# EXCEPTION IN EVENT HANDLER #############

If you did please include the entire error message i.e.

############# EXCEPTION IN EVENT HANDLER #############
other error message stuff here
######################################################

I see the exception when I try to install a handler (addEventHandler) on a sprite installed on a new class. See StartButton below. Things work when the handler is installed on a sprite hosted on the PApplet.

class StartButton 
{
  public Sprite sprite;
  
  StartButton(PApplet applet, int xpos, int ypos)
  {
    sprite = new Sprite(applet, "Start Button.png", 70);
    sprite.setXY(xpos, ypos);
    sprite.setVelXY(0, 0);
    //sprite.setScale(.5);

    sprite.respondToMouse(true);
    sprite.addEventHandler(this, "onButton");
  }
  
  void onButton(Sprite sprite)
  {
    println("ON BUTTON xxx" + sprite);
  }
}

Here is the full stack trace. No line numbers.

=======================================================
GameControlPlus V1.2.2 created by
Christian Riekoff and Peter Lager

java.lang.NullPointerException
at sprites.SMessenger.eventHandlerFailed(Unknown Source)
at sprites.SMessenger.message(Unknown Source)
at sprites.Sprite.fireEvent(Unknown Source)
at sprites.Sprite.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1436)
NullPointerException
at processing.core.PApplet.handleMethods(PApplet.java:1638)
at processing.core.PApplet.handleMouseEvent(PApplet.java:2749)
at processing.core.PApplet.dequeueEvents(PApplet.java:2652)
at processing.core.PApplet.handleDraw(PApplet.java:2493)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

Oh and I am also using GameControlPlus which is the additional banner printed before the stack trace.

OK we have to start somewhere so make this change

and see what happens.

The event handler must have public access.

Yes. Making both the class and the handler method public does the trick. Thanks!.

Yes. Making both the class and the handler method public does the trick. Thanks!.