calling an java function

90 views
Skip to first unread message

Kishore Prabhu Radhakrishnan

unread,
Jan 28, 2021, 12:02:59 PM1/28/21
to j2objc-discuss
Hi Tom,

I am not able to find any clear tutorial for calling an java function  in swift(ViewController.swift) and I am struck up with that for hours, Please can you help me on that

1. Calling a java function once other stuffs are done

Thanks
Kishore

whende...@gmail.com

unread,
Jan 28, 2021, 12:36:38 PM1/28/21
to j2objc-discuss
You don't, exactly.  You convert the java to obj-C and call that.  Here are some references that may help you:
Once you have gotten things successfully set up, for instance your converted java code now in a folder in your Xcode project called myJava, you can call the functions in that folder:  variableToSet = myJava().myFunction()

Tom Ball

unread,
Jan 28, 2021, 2:15:51 PM1/28/21
to j2objc-...@googlegroups.com
Check out the Hello-Swift example. 

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/c021dfdb-a20d-4329-8268-8e6ae8cf90b6n%40googlegroups.com.

Kishore Prabhu Radhakrishnan

unread,
Jan 28, 2021, 9:01:16 PM1/28/21
to j2objc-discuss
Hi Tom

This is my basic java code and I need to call the checkDemo() function in the SharedJavaCode class
1.how to call the function in swift


I have tried 
let object = SharedJavaCode()     //but it says SharedJavaCode not in scope



I read the above example(HelloSwift) you mention also

OrgJ2objcExample , OrgJ2objcExample_Day => how was these created 

Please can you help me accessing the java class

Screenshot 2021-01-29 at 7.23.40 AM.png

Tom Ball

unread,
Jan 29, 2021, 12:00:16 AM1/29/21
to j2objc-discuss
Your project doesn't show a bridging header, so drop all j2objc-related experiments and instead read how to import Objective-C into a Swift project. All j2objc does is generate Objective-C sources which define Objective-C classes, so until you learn how to import Objective-C classes there can be no way your Swift code can access Java.

As was pointed out before, the j2objc-2.7/examples/HelloSwift/HelloSwift.xcodeproj/ is a very simple example of how to access Java-based code from Swift. Open it, review its files and project settings. It's all there.

Calling a Java method a "function" suggests that you haven't worked with Java before. If that's the case, stop all use of j2objc and instead find an online beginning Android course. j2objc is NOT a learning aid, it's an advanced software engineering tool with some very sharp edges.

If you are looking for a cross-platform mobile development solution, consider Flutter. It uses a different language, Dart, but that's easy to learn if you are familiar with Swift. You only need to write the app once, then build it for Android and iOS from within its IDE.

Message has been deleted

Kishore Prabhu Radhakrishnan

unread,
Jan 29, 2021, 4:56:07 AM1/29/21
to j2objc-discuss
Path has been changed for the bridingheader.h file
I fixed it thanks a lot
Reply all
Reply to author
Forward
0 new messages