0

我从这里下载了 achartengine 演示:http ://code.google.com/p/achartengine/downloads/list 在我开始演示之后,我发现并不是每个图表都按预期绘制,当我点击预算饼图时,它没有用,这是我的日志:

06-11 17:48:31.478: D/AndroidRuntime(1909): Shutting down VM
06-11 17:48:31.478: W/dalvikvm(1909): threadid=1: thread exiting with uncaught exception (group=0x40a221f8)
06-11 17:48:31.518: E/AndroidRuntime(1909): FATAL EXCEPTION: main
06-11 17:48:31.518: E/AndroidRuntime(1909): java.lang.NullPointerException
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:692)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:103)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at org.achartengine.GraphicalView.onDraw(GraphicalView.java:174)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.draw(View.java:10982)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.getDisplayList(View.java:10421)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.draw(View.java:10985)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.getDisplayList(View.java:10421)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.getDisplayList(View.java:10419)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.draw(View.java:10985)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2126)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.View.getDisplayList(View.java:10421)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:840)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewRootImpl.draw(ViewRootImpl.java:1935)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1659)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2467)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.os.Looper.loop(Looper.java:137)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at java.lang.reflect.Method.invokeNative(Native Method)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at java.lang.reflect.Method.invoke(Method.java:511)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-11 17:48:31.518: E/AndroidRuntime(1909):     at dalvik.system.NativeStart.main(Native Method)

我无法在代码中捕获异常详细信息,可能是因为异常没有发生在主线程中。有人有同样的经历吗?欢迎任何相关的答案,提前谢谢!

4

1 回答 1

1

这本身可能与 AChartEngine 的演示应用程序没有直接关系。但是,我发现在使用 ProGuard 在发布模式下构建应用程序(使用 AChartEngine 库)时。正如ProGuard的 android 文档中所述,在某些情况下,它发现难以分析并错误地删除了它认为未使用的代码。在这种情况下,当库尝试通过调用 onDraw 来绘制图形时,它会引发 NPE。

为了克服这个问题,我发现您必须自定义 ProGuard 配置,以通过在 proguard.cfg 中添加以下行来指示它单独保留 AChartEngine 类。

-keep class javax.** { *; }

希望这可以帮助某人。

于 2014-03-13T10:21:55.523 回答