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

ava.lang.NullPointerException: Attempt to invoke virtual method 'void com.ramijemli.percentagechartview.renderer.BaseModeRenderer.setProgress(float, boolean)' on a null object reference #27

Open
yams585 opened this issue Jun 15, 2020 · 11 comments

Comments

@yams585
Copy link

yams585 commented Jun 15, 2020

Using a progressbar if I rotate the screen a few times or try to reload a few times eventually the library crashes with
Process: com.phpni.member_android, PID: 6451
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ramijemli.percentagechartview.renderer.BaseModeRenderer.setProgress(float, boolean)' on a null object reference
at com.ramijemli.percentagechartview.PercentageChartView.setProgress(PercentageChartView.java:421)

@vedprakashwagh
Copy link

I have almost the same issue, except it crashes with the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ramijemli.percentagechartview.renderer.BaseModeRenderer.destroy()' on a null object reference
        at com.ramijemli.percentagechartview.PercentageChartView.onDetachedFromWindow(PercentageChartView.java:175)
        at android.view.View.dispatchDetachedFromWindow(View.java:21362)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:4641)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:6287)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:6258)
        at android.view.ViewGroup.removeView(ViewGroup.java:6189)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:973)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
        at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7860)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

@BorisLegovic
Copy link

Same problem here: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ramijemli.percentagechartview.renderer.BaseModeRenderer.setProgress(float, boolean)' on a null object reference

I was not able to simulate error, but I got it in the crash report.

@yams585
Copy link
Author

yams585 commented Jun 24, 2020

@BorisLegovic all you have to do is turn your phone a few times and you'll see that npe thrown.

@yams585
Copy link
Author

yams585 commented Jun 24, 2020

I'm handling on resume so this shouldn't be thrown.

@vedprakashwagh
Copy link

I solved this error by importing library manually in the app, and then running the app. This is occurred because of

@Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if(renderer!=null) {
            renderer.destroy();
        }
        renderer = null;

        if (onProgressChangeListener != null) {
            onProgressChangeListener = null;
        }
    }

When the View is detached from Window, renderer object is destroyed. And this happens when you lock the device or when the view is basically detached. I solved it by commenting the renderer part in onDetachedFromWindow() so it doesn't get destroyed. The thing is this might cause memory leak, but I haven't seen any issue in my app after seeing the profiler, so I guess you should be fine.

@rkarimi88
Copy link

Hi.
Your library is great, but I have the same problem. May I ask you to update the library please?

I also have problem in adding library to project manually. So I can't use the solution given by "vedprakashwagh".

Thanks in advance.

@vladimir-petric
Copy link

Yes, I am experiencing this same issue. And @vedprakashwagh is right about the cause of the problem, I had the same conclusion

@anilejder
Copy link

I faced this problem too. However, I have used it in bottom sheet dialog. So, I remove whole the view with binding.root.removeAllViews() in onDismiss(). Keep in mind.

@VishalNehra
Copy link

For me the stacktrace was in onSaveInstanceState

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float com.ramijemli.percentagechartview.renderer.BaseModeRenderer.getStartAngle()' on a null object reference
        at com.ramijemli.percentagechartview.PercentageChartView.onSaveInstanceState(PercentageChartView.java:198)
        at android.view.View.dispatchSaveInstanceState(View.java:20797)
        at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3992)
        at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3992)
        at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3992)

My activity don't really need to save state, it's rotation is locked anyways, so I've used
percentageChartView.isSaveEnabled = false

@khizarhayat
Copy link

I was facing same issue in stack trace it was clear that it is coming in onDestroyView so instead i download library code i extend PercentageChartView and override method

override fun onDetachedFromWindow() {
    try {
        super.onDetachedFromWindow()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

@samantrader
Copy link

I solved this error by importing library manually in the app, and then running the app. This is occurred because of

@Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if(renderer!=null) {
            renderer.destroy();
        }
        renderer = null;

        if (onProgressChangeListener != null) {
            onProgressChangeListener = null;
        }
    }

When the View is detached from Window, renderer object is destroyed. And this happens when you lock the device or when the view is basically detached. I solved it by commenting the renderer part in onDetachedFromWindow() so it doesn't get destroyed. The thing is this might cause memory leak, but I haven't seen any issue in my app after seeing the profiler, so I guess you should be fine.

Hi
where is put this code exactly ?

thanks

igorka48 added a commit to igorka48/PercentageChartView that referenced this issue May 30, 2023
igorka48 added a commit to igorka48/PercentageChartView that referenced this issue May 30, 2023
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

9 participants