Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
Hello Elias, *First of all, Thank you very much for help. :)* *After I remove the static from function it worked well. * *Thanks* On Thursday, September 12, 2019 at 4:31:05 PM UTC+5:30, Elias Naur wrote: > > On Thu Sep 12, 2019 at 2:35 AM Jay Sharma wrote: > > > > *Hello Elias,* > > > > *Following is my java file: * > > > > > > package reversebinding; > > > > public class RBinding { > > public static String getStringFromJava() { > > return "Hello from java !!"; > > } > > } > > > > > > > > Your Java method is declared as "static"; static methods are exported as > regular functions in reverse bindings. Remove "static" and you might have > better luck calling it. > > > > > *I tried the following in my go file : * > > > > > > > > import "Java/reversebinding/RBinding" > > > > > > // creating object like this: > > > > javaObj := JavaAPI.New() > > javaObj.GetStringFromJava() > > > > *But while building using the gomobile it is giving following error: * > > JavaObj.GetStringFromJava undefined (type Java.Reversebinding_JavaAPI > has > > no field or method GetStringFromJava) > > undefined: val > > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a6fec9a3-928c-4539-ba95-ac9dd453a7c0%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
*Hello Elias,* *Following is my java file: * package reversebinding; public class RBinding { public static String getStringFromJava() { return "Hello from java !!"; } } *I tried the following in my go file : * import "Java/reversebinding/RBinding" // creating object like this: javaObj := JavaAPI.New() javaObj.GetStringFromJava() *But while building using the gomobile it is giving following error: * JavaObj.GetStringFromJava undefined (type Java.Reversebinding_JavaAPI has no field or method GetStringFromJava) undefined: val *If I call using class name: it is working fine. but with object it is not working.* *Can you please provide your suggestion ? * *Thanks.* On Thursday, September 12, 2019 at 1:14:21 PM UTC+5:30, Jay Sharma wrote: > > Hello Elias, > > Following are the lines from proposals: > Creating new Java instances > > To create a new instance of a Java class, use the New function defined in > the class package. For example: > > import ( > "Java/java/lang/Object" "Java/java/lang" > ) > > func NewObject() lang.Object { > return Object.New() > } > > *How can I modify it for my class ? * > > I know, It is too much to ask. I got confused. > > *Thanks for your help.* > > > > > On Wednesday, September 11, 2019 at 9:41:13 PM UTC+5:30, Elias Naur wrote: >> >> On Wed Sep 11, 2019 at 7:20 AM Jay Sharma wrote: >> > >> > >> > *Now, I want to create object of this class in go and want to call >> method >> > using that object from go. * >> > >> > I was checking your proposal (https://github.com/golang/go/issues/16876) >> >> > but could not able to make it. :( >> >> The proposal suggests calling the generated New method on the object. >> Did you try that? If so, what went wrong? >> >> -- elias >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/36a1de11-0a4b-478c-94b2-a01d8f2f4fc4%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
Hello Elias, Following are the lines from proposals: Creating new Java instances To create a new instance of a Java class, use the New function defined in the class package. For example: import ( "Java/java/lang/Object" "Java/java/lang" ) func NewObject() lang.Object { return Object.New() } *How can I modify it for my class ? * I know, It is too much to ask. I got confused. *Thanks for your help.* On Wednesday, September 11, 2019 at 9:41:13 PM UTC+5:30, Elias Naur wrote: > > On Wed Sep 11, 2019 at 7:20 AM Jay Sharma wrote: > > > > > > *Now, I want to create object of this class in go and want to call > method > > using that object from go. * > > > > I was checking your proposal (https://github.com/golang/go/issues/16876) > > > but could not able to make it. :( > > The proposal suggests calling the generated New method on the object. > Did you try that? If so, what went wrong? > > -- elias > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3de11f3c-62e5-4136-bf34-29e703085b98%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
*Thank you very much Elias : with your suggestion it is working fine.* Just last query: Currently, I called *static method* of my java class: package reversebinding; public class RBinding { public static String getStringFromJava() { return "Hello from java !!"; } } *Now, I want to create object of this class in go and want to call method using that object from go. * I was checking your proposal (https://github.com/golang/go/issues/16876) but could not able to make it. :( Can you please help me , how to do that? *Thanks*. On Wednesday, September 11, 2019 at 4:36:20 PM UTC+5:30, Elias Naur wrote: > > On Wed Sep 11, 2019 at 3:51 AM Jay Sharma wrote: > > > > > > I have one doubt when we build using gomobile in that I am giving the > > classpath to my .class java file. > > *Will it be included in .aar or I have to include that .class file along > > with .aar in my android application. * > > > > The class file is not automatically included, that wasn't clear from my > earlier > reply. Please include the class file in your project and try my suggestion > to > call your code from Java. > > -- elias > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a486225f-f2f9-49d3-856c-11495c8dce78%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
Hi Elias, The provided logs: 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:134: testFunction [Test] 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:136: [Test] Now going to call a java system function (System.CurrentTimeMillis()).. 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:138: [Test] Called java function return value is: 1568113614199 *In this you can see I am able to call System.CurrentTimeMillis() and printing in logs.* *This is the next line of code where I am trying to call my own class java function from go: * 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:140: [Test] Now going to call my java function After this log I am actually calling like this: *RBinding.getStringFromJava() and it is crashing. * I have one doubt when we build using gomobile in that I am giving the classpath to my .class java file. *Will it be included in .aar or I have to include that .class file along with .aar in my android application. * Thanks. On Tuesday, September 10, 2019 at 8:55:47 PM UTC+5:30, Elias Naur wrote: > > On Tue Sep 10, 2019 at 4:26 AM Jay Sharma wrote: > > --=_Part_1258_983331168.1568114760099 > > Content-Type: text/plain; charset="UTF-8" > > > > Hello @elias, > > > > I tried the following: > > > > 1. Created a java class : > > > > package reversebinding; > > > > public class RBinding { > > public static String getStringFromJava() { > > return "Hello from java !!"; > > } > > } > > > > 2. Generated the .class file for this file. > > > > 3. Generated the android binding using gomobile tool and used > > -classpath="Path to my .class file" > > > > 4. Binding is generated successfully. > > > > *But when I used that generated (.aar) file in my android app and tried > to > > trigger the api it is crashing; * > > > > 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 > 11:06:54 > > test.go:134: testFunction [Test] > > 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 > 11:06:54 > > test.go:136: [Test] Now going to call a java system function > > (System.CurrentTimeMillis()). > > 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 > 11:06:54 > > test.go:138: [Test] Called java function return value is: 1568113614199 > > 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 > 11:06:54 > > test.go:140: [Test] Now going to call my java function. > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: panic: runtime error: > > invalid memory address or nil pointer dereference > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: [signal SIGSEGV: > > segmentation violation code=0x1 addr=0x0 pc=0x7568010708] > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: goroutine 17 [running, > > locked to thread]: > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > > test.testFunction(0x400738) > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > > /home/test/2019/test/test.go:141 +0x190 > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > > main.proxytest__testFunction(...) > > 2019-09-10 16:36:54.203 9400-0/com.sample com.sample E/Go: > > /tmp/gomobile-work-071468276/src/gobind/go_testmain.go:199 > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > > > main._cgoexpwrap_5427a26f9204_proxytest__testFunction(0x8020080280200802) > > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: _cgo_gotypes.go:606 > > +0x1c > > 2019-09-10 16:36:54.204 9400-9423/com.sample A/libc: Fatal signal 6 > > (SIGABRT), code -6 in tid 9423 (Thread-2) > > > > The error is arguably not very helpful. Are you sure there is not another > error > before the nil pointer exception? In any case, did you ensure that the > .class > is included in the Android apk? An easy check is to try to call your > method > from Java before trying from Go. > > -- elias > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a5d988ed-b057-49e5-b419-6a7302e7bdd2%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
Just one more information: I am calling from my go code like this: RBinding.GetStringFromJava() On Tuesday, September 10, 2019 at 4:56:00 PM UTC+5:30, Jay Sharma wrote: > > Hello @elias, > > I tried the following: > > 1. Created a java class : > > package reversebinding; > > public class RBinding { > public static String getStringFromJava() { > return "Hello from java !!"; > } > } > > 2. Generated the .class file for this file. > > 3. Generated the android binding using gomobile tool and used > -classpath="Path to my .class file" > > 4. Binding is generated successfully. > > *But when I used that generated (.aar) file in my android app and tried to > trigger the api it is crashing; * > > 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 > test.go:134: testFunction [Test] > 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 > test.go:136: [Test] Now going to call a java system function > (System.CurrentTimeMillis()). > 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 > test.go:138: [Test] Called java function return value is: 1568113614199 > 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 > test.go:140: [Test] Now going to call my java function. > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: panic: runtime error: > invalid memory address or nil pointer dereference > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: [signal SIGSEGV: > segmentation violation code=0x1 addr=0x0 pc=0x7568010708] > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: goroutine 17 [running, > locked to thread]: > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > test.testFunction(0x400738) > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > /home/test/2019/test/test.go:141 +0x190 > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > main.proxytest__testFunction(...) > 2019-09-10 16:36:54.203 9400-0/com.sample com.sample E/Go: > /tmp/gomobile-work-071468276/src/gobind/go_testmain.go:199 > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: > main._cgoexpwrap_5427a26f9204_proxytest__testFunction(0x8020080280200802) > 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: _cgo_gotypes.go:606 > +0x1c > 2019-09-10 16:36:54.204 9400-9423/com.sample A/libc: Fatal signal 6 > (SIGABRT), code -6 in tid 9423 (Thread-2) > > *Can you please provide you opinion. Let me know if any other information > is needed. * > > Thanks > > > On Monday, September 9, 2019 at 5:40:25 PM UTC+5:30, Elias Naur wrote: >> >> On Mon Sep 9, 2019 at 3:09 AM Jay Sharma wrote: >> > >> > *Next I want to try with my own classes in java.. I want to define >> class >> > and call it from go. * >> > *Can you please suggest, in that case how to build with gomobile ?* >> > >> >> I think you can use the -classpath option to gomobile. >> >> -- elias >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9957ce97-b649-4733-9b46-2232f88c55a3%40googlegroups.com.
Re: [go-nuts] Re: x/mobile: Samples for reverse binding in gomobile
Hello @elias, I tried the following: 1. Created a java class : package reversebinding; public class RBinding { public static String getStringFromJava() { return "Hello from java !!"; } } 2. Generated the .class file for this file. 3. Generated the android binding using gomobile tool and used -classpath="Path to my .class file" 4. Binding is generated successfully. *But when I used that generated (.aar) file in my android app and tried to trigger the api it is crashing; * 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:134: testFunction [Test] 2019-09-10 16:36:54.199 9400-9430/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:136: [Test] Now going to call a java system function (System.CurrentTimeMillis()). 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:138: [Test] Called java function return value is: 1568113614199 2019-09-10 16:36:54.200 9400-9434/com.sample E/GoLog: 2019/09/10 11:06:54 test.go:140: [Test] Now going to call my java function. 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: panic: runtime error: invalid memory address or nil pointer dereference 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7568010708] 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: goroutine 17 [running, locked to thread]: 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: test.testFunction(0x400738) 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: /home/test/2019/test/test.go:141 +0x190 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: main.proxytest__testFunction(...) 2019-09-10 16:36:54.203 9400-0/com.sample com.sample E/Go: /tmp/gomobile-work-071468276/src/gobind/go_testmain.go:199 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: main._cgoexpwrap_5427a26f9204_proxytest__testFunction(0x8020080280200802) 2019-09-10 16:36:54.203 9400-0/com.sample E/Go: _cgo_gotypes.go:606 +0x1c 2019-09-10 16:36:54.204 9400-9423/com.sample A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 9423 (Thread-2) *Can you please provide you opinion. Let me know if any other information is needed. * Thanks On Monday, September 9, 2019 at 5:40:25 PM UTC+5:30, Elias Naur wrote: > > On Mon Sep 9, 2019 at 3:09 AM Jay Sharma wrote: > > > > *Next I want to try with my own classes in java.. I want to define class > > and call it from go. * > > *Can you please suggest, in that case how to build with gomobile ?* > > > > I think you can use the -classpath option to gomobile. > > -- elias > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ecc0ab8e-2f04-4f76-af41-664af8c1041a%40googlegroups.com.
[go-nuts] x/mobile: Samples for reverse binding in gomobile
Hello All, *I can not see any samples for reverse binding (Calling function from go layer of java layer) in gomobile.* Is anybody tried any samples of reverse binding. Thank in advance. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4e960e3d-e543-4735-a9ba-de23387dff16%40googlegroups.com.
[go-nuts] x/mobile: Launch a android application with given package name [String] in go
Hello All, *Following is the function written in go:* func LaunchApplication(packageName string) { Query : how can I execute application with given packageName } Generated the java binding [.aar] using *gomobile*. I want to include .aar generated in my android application and call *LaunchApplication("com.package.name")* from java layer to native go layer and go layer should run the application. *In java application*, following is the way to run apk using package name: Process process = Runtime.getRuntime().exec("am start -n com.package.name/com.package.name.ActivityName"); I tried the same in go using: *os.exec()* function but it is giving error that "am not found in the $PATH" *Is there is any way to do that ?* -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e96f0a4c-00dd-421e-ab6c-c0967369a90a%40googlegroups.com.
[go-nuts] Re: Regarding string immutablity
*@Jan*, The example you shown it is copying a string to new variable. but my question was related to same variable. I want to know if I have variable : x := "testsring" Now it overwrite the content of same variable x to some other value: x = "new1string" Will it overwrite the same memory or it will create some copy ? @Jake Montgomery, It is about *security*. I have some keys and I want to delete the content of key, when no longer required. Here my API is expecting a string key. On Tuesday, August 28, 2018 at 8:25:27 PM UTC+5:30, Jay Sharma wrote: > > Hi All, > > I went through documentation and many post. Every where it is specified > *strings > are immutable*. > > I have some string : > > x := "teststring" > > > I want to *wipe out/overwrite* the content of this string x from > disk/memory. > > As per me the simplest way to do this: > > x = "" > > > or If I want to overwrite it with some new content, I can do this: [*Here > length of new string is equal to length of old string*] > > x = "new1string" > > > As I am overwriting the content with new content, Is it *inplace > replacement* [same memory is being updated] or a new copy will be created > with new content and old content will be there in the memory ? > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Regarding string immutablity
Hi All, I went through documentation and many post. Every where it is specified *strings are immutable*. I have some string : x := "teststring" I want to *wipe out/overwrite* the content of this string x from disk/memory. As per me the simplest way to do this: x = "" or If I want to overwrite it with some new content, I can do this: [*Here length of new string is equal to length of old string*] x = "new1string" As I am overwriting the content with new content, Is it *inplace replacement* [same memory is being updated] or a new copy will be created with new content and old content will be there in the memory ? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.