B4J Question Inline Code Error - object is not an instance of declaring class

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to use the inline code but when I try to return a value it causes an error.

Anyone know why it's showing this error ?

I am using:
B4J Version 9.80
Java 14
Non-UI app

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals

End Sub

Sub AppStart (Args() As String)
    
    Dim jo As JavaObject = Me
    
    Dim s As String = jo.RunMethod("FirstMethod", Null)
    Log(s)
    
    StartMessageLoop
End Sub

#If JAVA
public String FirstMethod() {
   return "Hello World!";
}
#End If

Error that it displays is:
Error occurred on line: 15 (Main)
java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.main(main.java:30)
 

Daestrum

Expert
Licensed User
Longtime User
( note the static in the method signature )

B4X:
#If JAVA
public static String FirstMethod() {
   return "Hello World!";
}
#End If
 
Last edited:
Upvote 1
Top