yuxinburen / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

NPE in XYChart.toRealPoint() #253

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I can't reproduce the problem, but there was an orientation change involved as 
far as I could see. See stack trace below.

What version of the product binary library are you using?
1.0.0

Please provide any additional information below.

Here's the stack trace:

java.lang.NullPointerException
    at org.achartengine.chart.XYChart.toRealPoint(XYChart.java:805)
    at org.achartengine.tools.Pan.apply(Pan.java:74)
    at org.achartengine.TouchHandler.handleTouch(TouchHandler.java:126)
    at org.achartengine.GraphicalView.onTouchEvent(GraphicalView.java:286)
    at android.view.View.dispatchTouchEvent(View.java:7127)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
    at android.view.View.dispatchPointerEvent(View.java:7307)
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:125)
    at android.os.Looper.loop(Looper.java:124)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by christia...@gmail.com on 28 Oct 2012 at 5:17

GoogleCodeExporter commented 9 years ago
Issue 248 has been merged into this issue.

Original comment by dandrome...@gmail.com on 8 Jan 2013 at 12:29

GoogleCodeExporter commented 9 years ago
Fixed in SVN.

Original comment by dandrome...@gmail.com on 8 Jan 2013 at 1:35

GoogleCodeExporter commented 9 years ago
Just a question: Wouldn't it be better to supress handleTouch until View is 
drawn? 
Regards

Index: src/org/achartengine/GraphicalView.java
===================================================================
--- src/org/achartengine/GraphicalView.java (revision 439)
+++ src/org/achartengine/GraphicalView.java (working copy)
@@ -78,6 +78,8 @@
   private float oldX;
   /** The old y coordinate. */
   private float oldY;
+  /** Was the view already drawn? AChartEngine Bug #253*/
+  private boolean drawn=false;

   /**
    * Creates a new graphical view.
@@ -175,8 +177,18 @@
       canvas.drawBitmap(zoomOutImage, left + width - zoomSize * 1.75f, buttonY, null);
       canvas.drawBitmap(fitZoomImage, left + width - zoomSize * 0.75f, buttonY, null);
     }
+    setDrawn();
   }

+  private void setDrawn() {
+    drawn=true;
+  }
+  
+  
+  protected boolean isDrawn() {
+    return drawn;
+  }
+  
   /**
    * Sets the zoom rate.
    * 
@@ -282,7 +294,7 @@
       oldX = event.getX();
       oldY = event.getY();
     }
-    if (mRenderer != null && (mRenderer.isPanEnabled() || 
mRenderer.isZoomEnabled())) {
+    if (mRenderer != null && isDrawn() && (mRenderer.isPanEnabled() || 
mRenderer.isZoomEnabled())) {
       if (mTouchHandler.handleTouch(event)) {
         return true;
       }

Original comment by seidel.b...@googlemail.com on 9 Jan 2013 at 1:24

GoogleCodeExporter commented 9 years ago
I have added the code you suggested. However, I will keep the code I added 
before as well as I am not sure that was only happening on pan or zoom.

Original comment by dandrome...@gmail.com on 9 Jan 2013 at 1:37

GoogleCodeExporter commented 9 years ago
Issue 248 has been merged into this issue.

Original comment by dandrome...@gmail.com on 19 Mar 2013 at 7:38