pointerIndex超出范围的Android多点触控 [英] pointerIndex out of range Android multitouch
问题描述
我有一个触摸事件的异常是导致我的游戏崩溃的平板电脑(或者更具体地说,蜂窝)...我的游戏能正常工作的我的电话,我还没有听说过这种情况发生的任何人,是不是运行Android 3.0或更高版本。下面是相关的日志信息...
I have a touch event exception that is causing my game to crash on tablets (or more specifically, honeycomb)... My game works fine on my phone and I haven't heard of this happening to anyone that isn't running Android 3.0 or higher. Here is the relevant log info...
E/AndroidRuntime(26487): java.lang.IllegalArgumentException: pointerIndex out of range
E/AndroidRuntime(26487): at android.view.MotionEvent.nativeGetAxisValue(Native Method)
E/AndroidRuntime(26487): at android.view.MotionEvent.getX(MotionEvent.java:1549)
E/AndroidRuntime(26487): at kieran.android.asteroids.GameUI.onTouchEvent(GameUI.java:665)
E/AndroidRuntime(26487): at android.view.View.dispatchTouchEvent(View.java:4616)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(26487): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291)
...这里是code正在调用它。似乎没什么问题,但也许有一个尚未修复又在蜂巢中的错误?该行号665从日志上述对应于浮法X = event.getX(ID);
行。它必须是与我正在这
变量可能的方式是什么?但它工作正常在手机/ 2.3,下...
... And here is the code that is calling it. Seems fine to me, but maybe there is a bug in honeycomb that hasn't been fixed yet? The line number 665 from the log above corresponds to the float x = event.getX(id);
line. It must have something to do with the way I am getting the which
variable maybe? But it works fine on the phones/2.3 and lower...
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
if(actionCode == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_UP) {
int which = action >> MotionEvent.ACTION_POINTER_ID_SHIFT;
int id = event.getPointerId(which);
float x = event.getX(id);
float y = event.getY(id);
任何帮助/想法将不胜AP preciated因为我试图让我的游戏提供给平板用户也是如此。谢谢你。
Any help/ideas would be greatly appreciated as I am trying to make my game available to tablet users as well. Thanks.
推荐答案
我的问题是,它实际上是调用event.getX(1)时,有没有实际两个ID。因此,我确信,有两个ID与event.getPointerCount()> = 2,它现在的作品。也许你就会有同样的运气!
My problem was that it was actually calling event.getX(1) when there wasn't actually two ids. So I made sure that there were two ids with event.getPointerCount() >= 2 and it now works. Maybe you'll have the same luck!
这篇关于pointerIndex超出范围的Android多点触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!