Open Johnson145 opened 6 years ago
me too, What is your solution? @Johnson145
Unfortunately, I don't have any solution yet. I was hoping to get some support here..
This happens to me too on orientation change.
Anybody checked out #3207 ? I'm not sure whether it will fix this issue, too, but I'll give it a shot.
Hi there, my PR will resolve this problem.
Thanks for your help. However, I implemented a different solution in #3763 that covers more use cases and tries to fix the broken references.
Thanks for your help. However, I implemented a different solution in #3763 that covers more use cases and tries to fix the broken references.
Excuse me, could you please explain how do I apply these changes with PirChartRenderer to my project? I am installing this library via gradle and I can't change source code. What sould I do ?
@poyarkov95 I don't think this hasn't been added yet. You have to manually download the repository from those pull requests into your android project to get the fixes. However I do hope to pull a fix soon into this main repository
Hi @almic , Will the fix be pulled soon into the repository? Thanks.
I'm using the library v3.1.0 and I have the same problem! Any solution?
I'm in the same case. I tried using the latest commit on the v3.1.0 but nothing changed.
Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference at mikephil.charting.renderer.PieChartRenderer.drawExtras(PieChartRenderer.java:669)
I don't have this error anymore, so if it can help someone else: It may be (I'm not sure) because I was trying to draw (at least change the parameters of) the pie chart before drawing the view.
Hi, thanks for the reply. I still have this error! Strange because it is only occurring on 1 smarthphone, all others work well! I'll test your tip !!
Hi Guys,
I'm still facing the same bug on version v3.1.0
. Any future version on roadmap to fix this problem?
Hi Guys,
I'm Have This Error With SDK 22 or Less , But work Good on SDK 23 or High.
Did anyone find the solution to this problem?
@AkshayChavan7
As a workaround you can create custom view that extends PieChart
and use this renderer.
class HackPieChartRenderer(
chart: PieChart,
animator: ChartAnimator,
viewPortHandler: ViewPortHandler
) : PieChartRenderer(chart, animator, viewPortHandler) {
override fun drawExtras(c: Canvas?) {
if (mDrawBitmap != null) {
super.drawExtras(c)
}
}
}
This works, because in my case bug was caused by view being 0dp tall. It was necessary for animation. And in that case mDrawBitmap
doesn't get initialised, which makes sense. But drawExtras(...)
still getting called.
Here the Java Version of @GaidamakUA's workaround. Create the class WorkaroundPieChartRenderer:
class WorkaroundPieChartRenderer extends PieChartRenderer {
public WorkaroundPieChartRenderer(PieChart chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(chart, animator, viewPortHandler);
}
@Override
public void drawExtras(Canvas c) {
if (mDrawBitmap != null) {
super.drawExtras(c);
}
}
}
Overwrite the Renderer as follows:
public class PieChartWithWorkaround extends PieChart {
...
public PieChartWithWorkaround(Context context) {
super(context);
setRenderer(new WorkaroundPieChartRenderer(this,this.mAnimator,this.mViewPortHandler));
...
}
}
我在运行时也出现了此问题,我一直尝试去从MPChart内部找解决方法,但是后面慢慢调试才发现在外部也可以找到解决方法。经过测试发现,是因为我的UI布局变化导致了PieChart显示不完全,之后我再xml文件中修改了布局结构这个问题就解决了。
I also encountered this problem when I was running. I have been trying to find a solution from within MPChart, but after slowly debugging, I found that a solution can also be found externally. After testing, it was found that the PieChart display was incomplete because of my UI layout changes. After that, I modified the layout structure in the xml file to solve the problem.
this happened to me if the layout_width
and/or layout_height
of the piechart in the activity/fragment xml is set to 0.
Any updates to this?, does the workaround included in the latest version?
this happened to me if the
layout_width
and/orlayout_height
of the piechart in the activity/fragment xml is set to 0.
I agree with @dalegaspi. The actual issue is the layout height. Just make sure your chart layout is showing "No Chart data Available" when added to layout. If for any reason in your layout its not showing properly, it will crash. This will resolve the crash. That's common sense, if there is no enough height to render stuff, it will crash.
mDrawBitmap
seems to be null and thereby causing a NullPointerException. Here is the full stacktrace:Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference at com.github.mikephil.charting.renderer.PieChartRenderer.drawExtras(PieChartRenderer.java:638) at com.github.mikephil.charting.charts.PieChart.onDraw(PieChart.java:131) at android.view.View.draw(View.java:16238) at android.view.View.updateDisplayListIfDirty(View.java:15235) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3637) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3617) at android.view.View.updateDisplayListIfDirty(View.java:15195) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.updateDisplayListIfDirty(View.java:15230) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.updateDisplayListIfDirty(View.java:15230) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.updateDisplayListIfDirty(View.java:15230) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.updateDisplayListIfDirty(View.java:15230) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.updateDisplayListIfDirty(View.java:15230) at android.view.View.draw(View.java:16008) at android.view.ViewGroup.drawChild(ViewGroup.java:3653) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3443) at android.view.View.draw(View.java:16241) at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2709) at android.view.View.updateDisplayListIfDirty(View.java:15235) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2681) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2495) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2124) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1140) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6232) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5551) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Unfortunately, I do not have further information about the potential cause of this error. However, I already received multiple occurences of this bug in Crashlytics.
Any help is appreciated very much!