B4J Question [SOLVED] OnTouchListener event

Star-Dust

Expert
Licensed User
Longtime User
I created a class that changes the event View as a parameter by changing the view. This works well in B4A but does not work in B4J.
This is the code:
B4X:
Sub Class_Globals
    Private CallBack As Object 'ignore
    Private EventName As String 'ignore
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(mCallBack As Object, mEventName As String)
    CallBack=mCallBack
    EventName=mEventName
End Sub

Public Sub ChangeTouchEvent(View As B4XView)
   
    #IF B4A
       Dim obj As Reflector
       obj.Target=View
       obj.SetOnTouchListener("ViewA_Touch")
    #ELSE IF B4J
        Dim jo As JavaObject = View
        Dim e As Object = jo.CreateEvent("android.view.View.OnTouchListener", "ViewJ", False)
        jo.RunMethod("setOnTouchListener", Array As Object(e))
       
    #ELSE IF B4i
   
    #End If
End Sub

Find the error :p .. Can anyone tell me why it does not work?

xxxxx.changetouchevent(java line: 87)
java.lang.ClassNotFoundException: android$view$View$OnTouchListener
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.createEvent(JavaObject.java:252)
at anywheresoftware.b4j.object.JavaObject.CreateEvent(JavaObject.java:215)
at b4j.example.dragdrop._adddragview(dragdrop.java:87)
at b4j.example.main._appstart(main.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
 

udg

Expert
Licensed User
Longtime User
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I copied Erel's example
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

like udg already pointed out, the code for B4J is wrong and should be:

B4X:
    Dim jo As JavaObject = View
    Dim e As Object = jo.CreateEvent("javafx.event.EventHandler", "ViewJ", False)
    jo.RunMethod("setOnTouchMoved", Array(e)) 'change the event to fit your purpose

Have a look at the Java documentation for a list of all events.

Jan
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank's SOLVED
 
Upvote 0
Top