我从这里下载了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)
我无法在代码中捕获异常细节,因为异常没有发生在主线程中。任何人都有相同的经历吗? 欢迎任何相关答案,提前谢谢!
答案 0 :(得分:1)
这可能与AChartEngine的演示应用程序本身无直接关系。但是我发现在使用ProGuard在发布模式下构建应用程序(使用AChartEngine库)时。正如ProGuard的android文档中所述,有些情况会发现难以分析并错误地删除它认为未使用的代码。在这种情况下,当库试图通过调用onDraw绘制图形时,它会抛出一个NPE。
为了解决这个问题,我发现您必须自定义ProGuard配置,通过将以下行添加到proguard.cfg来指示它单独保留AChartEngine类。
-keep class javax.** { *; }
希望这有助于某人。