Open Foivos-Stamopoulos opened 8 years ago
+1
In my case, addArcView()
is not being called.
+1, addArcView()
is not being called.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.jorgecastilloprz.progressarc.ProgressArcView.show()' on a null object reference
+1
+1
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.
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();
}
}
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 thefabProgressCircle
needs some time to instantiate?