我正在使用achartengine
并且在删除注释然后使用不同的 (x,y) 值再次添加它时得到 NullPointerException。这是代码:
for(int n = 0; n < series.getAnnotationCount(); ++n){
double x = toCoordinate(series.getAnnotationX(n)*prevTimeScale*1000, timeScale);
double y = series.getAnnotationY(n);
String text = series.getAnnotationAt(n);
series.removeAnnotation(n);
series.addAnnotation(n, text, x, y);
}
addAnnotation()
当前的ace框架中不存在带索引的方法,但我添加了它:
public void addAnnotation(int index, String annotation, double x, double y) {
mAnnotations.add(index, annotation);
mStringXY.put(index, x, y);
}
基本上,我在给定索引处删除注释,然后添加相同的文本但坐标不同。打电话后GraphicalView#repaint()
我得到这个NullPointerException
:
07-23 19:41:56.256: E/AndroidRuntime(17984): FATAL EXCEPTION: main
07-23 19:41:56.256: E/AndroidRuntime(17984): java.lang.NullPointerException
07-23 19:41:56.256: E/AndroidRuntime(17984): at org.achartengine.model.XYSeries.getAnnotationY(XYSeries.java:294)
07-23 19:41:56.256: E/AndroidRuntime(17984): at org.achartengine.chart.XYChart.draw(XYChart.java:310)
07-23 19:41:56.256: E/AndroidRuntime(17984): at org.achartengine.GraphicalView.onDraw(GraphicalView.java:177)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.draw(View.java:13717)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.buildDrawingCache(View.java:12971)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12634)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.draw(View.java:13433)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12653)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12593)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12593)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12593)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12593)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2910)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12593)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.View.getDisplayList(View.java:12699)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1198)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2173)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.Choreographer.doFrame(Choreographer.java:532)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.os.Handler.handleCallback(Handler.java:725)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.os.Handler.dispatchMessage(Handler.java:92)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.os.Looper.loop(Looper.java:137)
07-23 19:41:56.256: E/AndroidRuntime(17984): at android.app.ActivityThread.main(ActivityThread.java:5233)
07-23 19:41:56.256: E/AndroidRuntime(17984): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 19:41:56.256: E/AndroidRuntime(17984): at java.lang.reflect.Method.invoke(Method.java:511)
07-23 19:41:56.256: E/AndroidRuntime(17984): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
07-23 19:41:56.256: E/AndroidRuntime(17984): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
07-23 19:41:56.256: E/AndroidRuntime(17984): at dalvik.system.NativeStart.main(Native Method)
07-23 19:42:03.088: E/Trace(18186): error opening trace file: No such file or directory (2)
问题在于getAnnotationY(int index)
使用getYByIndex(int index)
的方法IndexXYMap
:
public V getYByIndex(int index) {
K key = indexList.get(index);
return this.get(key);
}
因为该行return this.get(key)
正在返回null
,我不知道为什么,因为我正在添加带有索引的注释。我正在使用来自 SVN 存储库的最新 ace 版本。
什么可能导致问题?先感谢您!