johannilsson / android-pulltorefresh

DEPRECATED This project aims to provide a reusable pull to refresh widget for Android.
2.47k stars 1.03k forks source link

IllegalArgumentException: historyPos out of range #37

Closed quiffman closed 13 years ago

quiffman commented 13 years ago

On android 3.2 - both Galaxy 10.1 and Acer A100, I see this behaviour when pulling to refresh:

E/AndroidRuntime(14918): FATAL EXCEPTION: main
E/AndroidRuntime(14918): java.lang.IllegalArgumentException: historyPos out of range
E/AndroidRuntime(14918):    at android.view.MotionEvent.nativeGetAxisValue(Native Method)
E/AndroidRuntime(14918):    at android.view.MotionEvent.getHistoricalY(MotionEvent.java:1828)
E/AndroidRuntime(14918):    at com.markupartist.android.widget.PullToRefreshListView.applyHeaderPadding(PullToRefreshListView.java:224)
E/AndroidRuntime(14918):    at com.markupartist.android.widget.PullToRefreshListView.onTouchEvent(PullToRefreshListView.java:195)
E/AndroidRuntime(14918):    at android.view.View.dispatchTouchEvent(View.java:4609)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1554)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1732)
E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1267)
E/AndroidRuntime(14918):    at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1705)
E/AndroidRuntime(14918):    at android.view.View.dispatchPointerEvent(View.java:4677)
E/AndroidRuntime(14918):    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2392)
E/AndroidRuntime(14918):    at android.view.ViewRoot.handleMessage(ViewRoot.java:2054)
E/AndroidRuntime(14918):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(14918):    at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime(14918):    at android.app.ActivityThread.main(ActivityThread.java:4123)
E/AndroidRuntime(14918):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(14918):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(14918):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(14918):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(14918):    at dalvik.system.NativeStart.main(Native Method)
quiffman commented 13 years ago

FWIW - I wonder if applyHeaderPadding should check getHistorySize - the following patch appears to solve the issue for me.

diff --git a/pulltorefresh/src/com/markupartist/android/widget/PullToRefreshListView.java b/pulltorefresh/src/com/markupartist/android/widget/PullToRefreshL
index e44db80..5ae52cc 100644
--- a/pulltorefresh/src/com/markupartist/android/widget/PullToRefreshListView.java
+++ b/pulltorefresh/src/com/markupartist/android/widget/PullToRefreshListView.java
@@ -203,7 +203,7 @@ public class PullToRefreshListView extends ListView implements OnScrollListener
         // (it's always 1 in 1.5)
         int pointerCount = 1;
         try {
-            Method method = MotionEvent.class.getMethod("getPointerCount");
+            Method method = MotionEvent.class.getMethod("getHistorySize");
             pointerCount = (Integer)method.invoke(ev);
         } catch (NoSuchMethodException e) {
             pointerCount = 1;
MikeBannion commented 13 years ago

Goot catch! but do you know if this fix only applies to tablets, or only from a specific Android version up? I just received a report on the market with this error and I'd like to apply the fix, but since my app is available for 1.6 devices as well I don't want to cause a break for other people...

johannilsson commented 13 years ago

Great finding. Would you like to send a pull request with the change or would you like me to just patch it?

johannilsson commented 13 years ago

If it's enough to use getHistorySize I guess we can skip the reflection part as well. Need to investigate that further.