pejmannikravan Member Feb 8, 2024 #1 hi dears, I made this class for testing: B4X: Copy #if java public class thisTest{ public thisTest(){ } } #End If Now I want to call and use this class with javaobject library: B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "thistest",Array(Null)) But I get the following error: java.lang.ClassNotFoundException: b4a$example$thistest at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:274) Click to expand...
hi dears, I made this class for testing: B4X: Copy #if java public class thisTest{ public thisTest(){ } } #End If Now I want to call and use this class with javaobject library: B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "thistest",Array(Null)) But I get the following error: java.lang.ClassNotFoundException: b4a$example$thistest at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:274) Click to expand...
Solution drgottjr Feb 8, 2024 Daestrum said: Make the class static Code: Copy #if java public static class thisTest{ ... #end if Click to expand... not this time, it seems. did you try it? this simple example: B4X: Copy Sub Activity_Create(FirstTime As Boolean) jo.InitializeNewInstance(Application.PackageName & ".main$thisTest",Array(Null)) End Sub #if Java public class thisTest{ public thisTest(){ BA.Log("here"); } } #End If runs for me (b4a 12.80, android 12). if i make the class static (which is what i normally would have done), i get a constructor not found error. i switched back and forth a number of times to make sure my eyes weren't up to their usual tricks. can you check it out?
Daestrum said: Make the class static Code: Copy #if java public static class thisTest{ ... #end if Click to expand... not this time, it seems. did you try it? this simple example: B4X: Copy Sub Activity_Create(FirstTime As Boolean) jo.InitializeNewInstance(Application.PackageName & ".main$thisTest",Array(Null)) End Sub #if Java public class thisTest{ public thisTest(){ BA.Log("here"); } } #End If runs for me (b4a 12.80, android 12). if i make the class static (which is what i normally would have done), i get a constructor not found error. i switched back and forth a number of times to make sure my eyes weren't up to their usual tricks. can you check it out?
DonManfred Expert Licensed User Longtime User Feb 8, 2024 #2 Inline Java Code The next versions of B4A (4.30) and B4J (2.80) will allow you to embed Java code inside your B4X code. B4i supports similar feature with Objective C. The purpose of this feature is to make it easier to access third party SDKs and also to allow developers to add existing Java code snippets to... www.b4x.com Just use static methods in java, not classes. It´s quite easy to call them. Upvote 0
Inline Java Code The next versions of B4A (4.30) and B4J (2.80) will allow you to embed Java code inside your B4X code. B4i supports similar feature with Objective C. The purpose of this feature is to make it easier to access third party SDKs and also to allow developers to add existing Java code snippets to... www.b4x.com Just use static methods in java, not classes. It´s quite easy to call them.
drgottjr Expert Licensed User Longtime User Feb 8, 2024 #3 what @DonManfred recommends, plus java is case-sensitive: "thistest" is not the same as "thisTest" in java. B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "[B]thistest[/B]",Array(Null)) public class [B]thisTest[/B]{ also, your instantiation is wrong: B4X: Copy Dim jo As JavaObject jo.InitializeNewInstance(Application.PackageName & [B]".main$thisTest[/B]",Array(Null)) Upvote 0
what @DonManfred recommends, plus java is case-sensitive: "thistest" is not the same as "thisTest" in java. B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "[B]thistest[/B]",Array(Null)) public class [B]thisTest[/B]{ also, your instantiation is wrong: B4X: Copy Dim jo As JavaObject jo.InitializeNewInstance(Application.PackageName & [B]".main$thisTest[/B]",Array(Null))
Daestrum Expert Licensed User Longtime User Feb 8, 2024 #4 Make the class static Code: Copy #if java public static class thisTest{ ... #end if Upvote 0
pejmannikravan Member Feb 8, 2024 #5 Thank you, I tried all the methods you said, but it was useless! It seems that I have to change my class to static. Upvote 0
Thank you, I tried all the methods you said, but it was useless! It seems that I have to change my class to static.
drgottjr Expert Licensed User Longtime User Feb 8, 2024 #6 Daestrum said: Make the class static Code: Copy #if java public static class thisTest{ ... #end if Click to expand... not this time, it seems. did you try it? this simple example: B4X: Copy Sub Activity_Create(FirstTime As Boolean) jo.InitializeNewInstance(Application.PackageName & ".main$thisTest",Array(Null)) End Sub #if Java public class thisTest{ public thisTest(){ BA.Log("here"); } } #End If runs for me (b4a 12.80, android 12). if i make the class static (which is what i normally would have done), i get a constructor not found error. i switched back and forth a number of times to make sure my eyes weren't up to their usual tricks. can you check it out? Attachments classtest.zip classtest.zip 7.2 KB · Views: 437 Upvote 0 Solution
Daestrum said: Make the class static Code: Copy #if java public static class thisTest{ ... #end if Click to expand... not this time, it seems. did you try it? this simple example: B4X: Copy Sub Activity_Create(FirstTime As Boolean) jo.InitializeNewInstance(Application.PackageName & ".main$thisTest",Array(Null)) End Sub #if Java public class thisTest{ public thisTest(){ BA.Log("here"); } } #End If runs for me (b4a 12.80, android 12). if i make the class static (which is what i normally would have done), i get a constructor not found error. i switched back and forth a number of times to make sure my eyes weren't up to their usual tricks. can you check it out?
Daestrum Expert Licensed User Longtime User Feb 8, 2024 #7 This is my java code Code: Copy public static class thisTest{ public thisTest(){} public void say(){ BA.Log("here"); } } And this is the code in B4A (B4XPages) Code: Copy Private Sub Button1_Click Dim myClass As JavaObject myClass.InitializeNewInstance("b4a.example.main$thisTest",Null) myClass.RunMethod("say",Null) xui.MsgboxAsync("Hello world!", "B4X") End Sub Upvote 0
This is my java code Code: Copy public static class thisTest{ public thisTest(){} public void say(){ BA.Log("here"); } } And this is the code in B4A (B4XPages) Code: Copy Private Sub Button1_Click Dim myClass As JavaObject myClass.InitializeNewInstance("b4a.example.main$thisTest",Null) myClass.RunMethod("say",Null) xui.MsgboxAsync("Hello world!", "B4X") End Sub
pejmannikravan Member Feb 8, 2024 #8 thank you @drgottjr and @Daestrum As you mentioned, the thistest class is a class of the main class, and this problem was solved by inserting main before the class name. Thanks Upvote 0
thank you @drgottjr and @Daestrum As you mentioned, the thistest class is a class of the main class, and this problem was solved by inserting main before the class name. Thanks
M Mitwellnessers New Member Mar 11, 2024 #9 pejmannikravan said: hi dears, I made this class for testing: B4X: Copy #if java public class thisTest{ public thisTest(){ } } #End If Now I want to call and use this class with javaobject library: B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "[URL='https://berufshaftpflichtversicherungen-heute.de/wellness/']t[/URL]histest",Array(Null)) But I get the following error: Click to expand... Thanks a lot Upvote 0
pejmannikravan said: hi dears, I made this class for testing: B4X: Copy #if java public class thisTest{ public thisTest(){ } } #End If Now I want to call and use this class with javaobject library: B4X: Copy Dim j2 As JavaObject=Me j2.InitializeNewInstance(Application.PackageName & "." & "[URL='https://berufshaftpflichtversicherungen-heute.de/wellness/']t[/URL]histest",Array(Null)) But I get the following error: Click to expand... Thanks a lot