Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception when calling show() function #29

Open
Foivos-Stamopoulos opened this issue Apr 12, 2016 · 8 comments
Open

Null Pointer Exception when calling show() function #29

Foivos-Stamopoulos opened this issue Apr 12, 2016 · 8 comments

Comments

@Foivos-Stamopoulos
Copy link

In the following code, if fabProgressCircle.show() is called outside the Handler (which delays it's excecution for 500 milliseconds), the App crashes with Null Pointer Exception for fabProgressCircle.show(). Why could this happen? Does the fabProgressCircle needs some time to instantiate?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_2);

    com.melnykov.fab.FloatingActionButton doneButton = (com.melnykov.fab.FloatingActionButton) findViewById(R.id.done2);
    com.github.jorgecastilloprz.FABProgressCircle fabProgressCircle = (com.github.jorgecastilloprz.FABProgressCircle) findViewById(R.id.fabProgressCircle );


    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            fabProgressCircle .show();
        }
    }, 500);
}
@thiagokimo
Copy link

+1

@thiagokimo
Copy link

thiagokimo commented Apr 25, 2016

In my case, addArcView() is not being called.

@mstedler
Copy link

mstedler commented Aug 13, 2016

+1, addArcView() is not being called.

@john1jan
Copy link

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.jorgecastilloprz.progressarc.ProgressArcView.show()' on a null object reference

@daniellessa
Copy link

+1

1 similar comment
@zhenalexfan
Copy link

+1

@helloray
Copy link

helloray commented Oct 11, 2016

After checking the library source code, addArcView() is called by onMeasure() method. As a result of that, you should not use the show function until the activity is completely shown. A good place to call show() is in onWindowFocusChanged(hasFocus == true) function .

@OverRide public void onWindowFocusChanged(boolean hasFocus) {

if (hasFocus == true)
  fabProgressCircle.show();

}

You should not use the show() function in OnCreate, OnResume, OnStart.

@wujushan
Copy link

wujushan commented Nov 27, 2017

You can modify the source code . Adding an OnGlobalLayoutListener before invoking the method show() will work for me

public void show() {
        if (progressArc == null) {
            this.getViewTreeObserver().addOnGlobalLayoutListener(
                    new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            if (progressArc != null) {
                                progressArc.show();
                                getViewTreeObserver().removeOnGlobalLayoutListener(this);
                            }
                        }
                    });
        }else {
            progressArc.show();
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants