Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
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

Copy link
Copy link
@ghost

Description

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.

Thanks in advance.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.