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(0x4000000738)
> > 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/a5d988ed-b057-49e5-b419-6a7302e7bdd2%40googlegroups.com.