Hi everyone,
I'm encountering a persistent java.lang.RuntimeException: Method: Initialize not matched error, even in a minimal project, when trying to call an inline Java method from B4A using JavaObject.RunMethod. I'm hoping someone can spot what I might be missing.
Environment:
Minimal B4A Code (Main.bas):
What I've Checked/Tried:
Any insights or suggestions would be greatly appreciated!
Thanks,
I'm encountering a persistent java.lang.RuntimeException: Method: Initialize not matched error, even in a minimal project, when trying to call an inline Java method from B4A using JavaObject.RunMethod. I'm hoping someone can spot what I might be missing.
Environment:
- B4A Version: 13.10
- Java Version (JDK): 19
- Target Android version (if relevant, though error is at compile/runtime linkage): Android 7 (from logs)
Minimal B4A Code (Main.bas):
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Dim Native As JavaObject = Me
Log("B4A: Calling Initialize with BA and WebView")
Native.RunMethod("Initialize", Array(Me, WebView1)) ' Me = reference to the activity BA object
Log("B4A: Call to InitializeJava finished.")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#if JAVA
import anywheresoftware.b4a.BA;
import android.webkit.WebView;
private static BA parent;
private static WebView webView;
public void Initialize(BA ba, WebView wv) {
parent = ba;
webView = wv;
BA.Log("✅ Java Initialize called. BA = " + parent);
}
#End If
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
B4A: Calling Initialize with BA and WebView
Error occurred on line: 36 (Main) 'Line where Native.RunMethod is called
java.lang.RuntimeException: Method: Initialize not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at b4a.web.main.afterFirstLayout(main.java:107) ' My package name is b4a.web
at b4a.web.main.access$000(main.java:19)
at b4a.web.main$WaitForLayout.run(main.java:85)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6161)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
** Activity (main) Resume **
What I've Checked/Tried:
- Signature Matching: The B4A call Native.RunMethod("Initialize", Array(Me, WebView1)) seems to perfectly match the Java instance method public void Initialize(BA ba, WebView wv).
- Me in B4A Activity is a BA instance.
- WebView1 is an android.webkit.WebView instance.
- Case Sensitivity: Checked that "Initialize" matches in both B4A and Java.
- Clean Project: I have tried cleaning the project and recompiling.
- Minimal Project: The code above is from a brand new, minimal project created just to test this, and the error persists.
- Static vs. Instance: I have also tried defining the Java method as static and calling it appropriately, but the "Method not matched" error remained (though the previous ClassCastException or cannot find symbol ba errors were when trying different Java structures). The current setup (B4A Native=Me calling a non-static Java method) seems like it should be the most straightforward.
Any insights or suggestions would be greatly appreciated!
Thanks,