You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Calling a @Background/@WakeLock method in a @AfterInject method causes NullPointerException #1466
Hi there, I'm experience a bug with AndroidAnnotations 3.3.1.
I have an @efragment support fragment with an @AfterInject method where I want to perform some initialization. Calling a @Background/@Wakelock annotated method from within the @AfterInject method results in a NullPointerException.
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.PowerManager$WakeLock android.os.PowerManager.newWakeLock(int, java.lang.String)' on a null object reference : ... )
Looking at the generated code I see this:
private void init_(Bundle savedInstanceState) {
OnViewChangedNotifier.registerOnViewChangedListener(this);
Resources resources_ = getActivity().getResources();
...
restoreSavedInstanceState_(savedInstanceState);
init(); <- This is my @AfterInject method
powerManager_ = ((PowerManager) getActivity().getSystemService(Context.POWER_SERVICE));
}
The problem is that the powerManager_ is initialized after calling my @AfterInject method and thus the NullPointerException.
Shouldn't any required System Components/Services be initialized before calling any annotated method?
The fix for this would be to call any annotated methods after having first the reference to the required System Components/Services.
Putting my initialization code in a @Afterviews method doesn't result in the same exception.
The injection of powerManager_ should be in init();, before calls to methods annotated with @AfterInject. This is indeed a bug, and it's caused by the fact that the annotation @WakeLock must be processed after other annotations and it's badly managed.
@WonderCsabo, We should refactor a bit this part to make handlers more independent. In init_ we should create a block or a method for both inject, afterInject, injectViews, afterInjectViews, etc... So that the order of the handlers won't matters anymore.
Hi there, I'm experience a bug with AndroidAnnotations 3.3.1.
I have an @efragment support fragment with an @AfterInject method where I want to perform some initialization. Calling a @Background/@Wakelock annotated method from within the @AfterInject method results in a NullPointerException.
Looking at the generated code I see this:
The problem is that the powerManager_ is initialized after calling my @AfterInject method and thus the NullPointerException.
Shouldn't any required System Components/Services be initialized before calling any annotated method?
The fix for this would be to call any annotated methods after having first the reference to the required System Components/Services.
Putting my initialization code in a @Afterviews method doesn't result in the same exception.
Thanks in advance.