public class AddItemButton extends ImageButton implements OnClickListener {
@Inject
private EventManager eventManager;
public AddItemButton(Context context) {
super(context);
setOnClickListener(this);
}
public AddItemButton(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
setOnClickListener(this);
}
@Override
public void onClick(View view) {
eventManager.fire(new ButtonClickEvent(getId()));
}
}
But this gives me a null pointer exception because eventManager is null.
08-08 19:11:41.262: E/AndroidRuntime(20272): java.lang.NullPointerException
08-08 19:11:41.262: E/AndroidRuntime(20272): at org.ak80.alar.view.AddItemButton.onClick(AddItemButton.java:36)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.view.View.performClick(View.java:4438)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.view.View$PerformClick.run(View.java:18422)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.os.Handler.handleCallback(Handler.java:733)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.os.Handler.dispatchMessage(Handler.java:95)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.os.Looper.loop(Looper.java:136)
08-08 19:11:41.262: E/AndroidRuntime(20272): at android.app.ActivityThread.main(ActivityThread.java:5001)
08-08 19:11:41.262: E/AndroidRuntime(20272): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 19:11:41.262: E/AndroidRuntime(20272): at java.lang.reflect.Method.invoke(Method.java:515)
08-08 19:11:41.262: E/AndroidRuntime(20272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-08 19:11:41.262: E/AndroidRuntime(20272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-08 19:11:41.262: E/AndroidRuntime(20272): at dalvik.system.NativeStart.main(Native Method)
I think it maybe that EventManager is missing the Context / Activity. Can someone please help me to understand how to achieve my goal?
--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roboguice+...@googlegroups.com.
To post to this group, send email to robo...@googlegroups.com.
Visit this group at http://groups.google.com/group/roboguice.
For more options, visit https://groups.google.com/d/optout.
--