简体   繁体   English

反射库-调用RunStaticMethod返回错误

[英]Reflection library - call to RunStaticMethod returns error

i am trying to call the MotionEvent.obtain Methode using the reflections library. 我试图使用反射库调用MotionEvent.obtain Methode。 But so far i am not very successful. 但是到目前为止,我还不是很成功。 Everything i try results in the same error... Here my code from a button-click: 我尝试的所有操作都会导致相同的错误...在这里,我的代码来自于单击按钮:

Dim upTime As Long
Dim ev As Object
Dim args(12) As Object
Dim types(12) As String

upTime = Obj1.RunStaticMethod("android.os.SystemClock", "uptimeMillis", Null, Null)

'public static MotionEvent obtain (Long downTime, Long eventTime, Int action, Float x, Float y, Float pressure, Float size, Int metaState, Float xPrecision, Float yPrecision, Int deviceId, Int edgeFlags)
'Since: API Level 1
'Create a new MotionEvent, filling in all of the basic values that define the motion.
'Parameters:
'downTime   The time (in ms) when the user originally pressed down To start a stream of position events. This must be obtained from uptimeMillis().
args(0) = upTime
types(0) = "java.lang.long"
'eventTime  The the time (in ms) when this specific event was generated. This must be obtained from uptimeMillis().
args(1) = upTime
types(1) = "java.lang.long"
'action The kind of action being performed, such As ACTION_DOWN.
args(2) = "1" 'MotionEvent.ACTION_UP
types(2) = "java.lang.int"
'x  The X coordinate of this event.
args(3) = "50.0"
types(3) = "java.lang.float"
'y  The Y coordinate of this event.
args(4) = "20.0"
types(4) = "java.lang.float"
'pressure   The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) To 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
args(5) = "1.0"
types(5) = "java.lang.float"
'size   A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding To the finger touch Is normalized with a device specific range of values AND scaled To a value between 0 AND 1.
args(6) = "1.0"
types(6) = "java.lang.float"
'metaState  The state of any meta / modifier keys that were in effect when the event was generated.
args(7) = "0"
types(7) = "java.lang.int"
'xPrecision The precision of the X coordinate being reported.
args(8) = "1.0"
types(8) = "java.lang.float"
'yPrecision The precision of the Y coordinate being reported.
args(9) = "1.0"
types(9) = "java.lang.float"
'deviceId   The id For the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
args(10) = "0"
types(10) = "java.lang.int"
'edgeFlags  A bitfield indicating which edges, If any, were touched by this MotionEvent.
args(11) = "0"
types(11) = "java.lang.int"
'call methode
***ev = Obj2.RunStaticMethod("android.view.MotionEvent", "obtain", args, types)***

Here the error occurs (java.lang.IllegalArgumentException: argument type mismatch): 此处发生错误(java.lang.IllegalArgumentException:参数类型不匹配):

10-09 09:02:26.951: ERROR/B4A(296): ev = Obj2.RunStaticMethod("android.view.MotionEvent", "obtain", args, types)

10-09 09:02:26.961: ERROR/B4A(296): java.lang.IllegalArgumentException: argument type mismatch 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invokeNative(Native Method) 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invoke(Method.java:521) 10-09 09:02:26.961: ERROR/B4A(296): at anywheresoftware.b4a.agraham.reflection.Reflection.RunStaticMethod(Reflection.java:860) 10-09 09:02:26.961: ERROR/B4A(296): at anywheresoftware.b4a.agraham.reflectiondemo.main._button2_click(main.java:564) 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invokeNative(Native Method) 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invoke(Method.java:521) 10-09 09:02:26.961: ERROR/B4A(296): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105) 10-09 09:02:26.961: ERROR/B4A(296): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93) 10-09 09:02:26.961: ERROR/B4A(296): at anywheresoftware.b4a.BA.raiseEvent(BA.java:89) 10-09 09:02:26.961: ERROR/B4A(296): at 10-09 09:02:26.961:ERROR / B4A(296):java.lang.IllegalArgumentException:参数类型不匹配10-09 09:02:26.961:ERROR / B4A(296):java.lang.reflect.Method。 invokeNative(本机方法)10-09 09:02:26.961:ERROR / B4A(296):at java.lang.reflect.Method.invoke(Method.java:521)10-09 09:02:26.961:ERROR / B4A (296):在任何地方software.b4a.agraham.reflection.Reflection.RunStaticMethod(Reflection.java:860)10-09 09:02:26.961:ERROR / B4A(296):在任何地方software.b4a.agraham.reflectiondemo.main。 _button2_click(main.java:564)10-09 09:02:26.961:ERROR / B4A(296):at java.lang.reflect.Method.invokeNative(Native Method)10-09 09:02:26.961:ERROR / B4A (296):在java.lang.reflect.Method.invoke(Method.java:521)10-09 09:02:26.961:ERROR / B4A(296):在任何地方software.b4a.BA.raiseEvent2(BA.java: 105)10-09 09:02:26.961:ERROR / B4A(296):在任何地方software.b4a.BA.raiseEvent2(BA.java:93)10-09 09:02:26.961:ERROR / B4A(296):at Anywheresoftware.b4a.BA.raiseEvent(BA.java:89)10-09 09:02:26.961:ERROR / B4A(296):at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49) 10-09 09:02:26.961: ERROR/B4A(296): at android.view.View.performClick(View.java:2408) 10-09 09:02:26.961: ERROR/B4A(296): at android.view.View$PerformClick.run(View.java:8816) 10-09 09:02:26.961: ERROR/B4A(296): at android.os.Handler.handleCallback(Handler.java:587) 10-09 09:02:26.961: ERROR/B4A(296): at android.os.Handler.dispatchMessage(Handler.java:92) 10-09 09:02:26.961: ERROR/B4A(296): at android.os.Looper.loop(Looper.java:123) 10-09 09:02:26.961: ERROR/B4A(296): at android.app.ActivityThread.main(ActivityThread.java:4627) 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invokeNative(Native Method) 10-09 09:02:26.961: ERROR/B4A(296): at java.lang.reflect.Method.invoke(Method.java:521) 10-09 09:02:26.961: ERROR/B4A(296): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 10-09 09:02:26.961: ERROR/B4A(296): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: Anywheresoftware.b4a.objects.ViewWrapper $ 1.onClick(ViewWrapper.java:49)10-09 09:02:26.961:ERROR / B4A(296):at android.view.View.performClick(View.java:2408)10- 09 09:02:26.961:ERROR / B4A(296):在android.view.View $ PerformClick.run(View.java:8816)10-09 09:02:26.961:ERROR / B4A(296):在android。 os.Handler.handleCallback(Handler.java:587)10-09 09:02:26.961:ERROR / B4A(296):at android.os.Handler.dispatchMessage(Handler.java:92)10-09 09:02: 26.961:ERROR / B4A(296):在android.os.Looper.loop(Looper.java:123)10-09 09:02:26.961:ERROR / B4A(296):在android.app.ActivityThread.main(ActivityThread .java:4627)10-09 09:02:26.961:ERROR / B4A(296):at java.lang.reflect.Method.invokeNative(Native Method)10-09 09:02:26.961:ERROR / B4A(296) :at java.lang.reflect.Method.invoke(Method.java:521)10-09 09:02:26.961:ERROR / B4A(296):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit .java:868)10-09 09:02:26.961:ERROR / B4A(296):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 626) 10-09 09:02:26.961: ERROR/B4A(296): at dalvik.system.NativeStart.main(Native Method) 10-09 09:02:26.961: ERROR/B4A(296): java.lang.IllegalArgumentException: argument type mismatch 626)10-09 09:02:26.961:ERROR / B4A(296):在dalvik.system.NativeStart.main(本机方法)10-09 09:02:26.961:ERROR / B4A(296):java.lang。 IllegalArgumentException:参数类型不匹配

Dim args1(1) As Object
Dim types1(1) As String
args1(0) = ev
types1(0) = "android.view.MotionEvent"

Obj2.Target = Activity
Obj2.RunStaticMethod("android.view.View","dispatchTouchEvent",args1,types1)

Any help would be great... Thank you, Richard. 任何帮助都会很棒...谢谢你,理查德。

Did you see the Multitouch tutorial? 您看到Multitouch教程了吗? Maybe the Gestures library already does what you need. 也许手势库已经可以满足您的需求。

Anyway you can do it with this code: 无论如何,您可以使用以下代码进行操作:

Sub Activity_Create(FirstTime As Boolean)
    Dim me As Object
    me = ObtainMotionEvent(1000, 1000, 1, 100, 100, 500, 500, 0, 100, 100, 0, 0)
    Log(me)
End Sub


Sub ObtainMotionEvent(DownTime As Long, EventTime As Long, Action As Int, _
    X As Float, Y As Float, Pressure As Float, Size As Float, MetaState As Int, _
    XPrecision As Float, YPrecision As Float, DeviceId As Int, EdgeFlags As Int) As Object
    Dim r As Reflector
    Dim f, i As String
    f = "java.lang.float"
    i = "java.lang.int"
    l = "java.lang.long"
    Return r.RunStaticMethod("android.view.MotionEvent", "obtain", _
        Array As Object(DownTime, EventTime, Action, X, Y, Pressure, Size, MetaState, _
            XPrecision, YPrecision, DeviceId, EdgeFlags), _
        Array As String(l, l, i, f, f, f, f, i, f, f, i, i))
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM