Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why isn't this working? jclass pointer  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jclass pointer and I'm attempting to set it equal to GetObjectClass, but it keeps throwing a JVM error. The GetObjectClass returns properly but when i try to set the value of the pointer it craps out.

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Storing data at address 0 is, by definition, a segfault, and that's what you're doing here. "jclass * classPointer = NULL" creates a pointer which points to address 0, and "*classPointer = ..." sets address 0 to a value. You want to declare the function as taking a jclass**, and you want to pass &classPointer as the argument to the function; the code inside the function can then stay.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Storing data at address 0 is, by definition, a segfault, and that's what you're doing here. "jclass * classPointer = NULL" creates a pointer which points to address 0, and "*classPointer = ..." sets address 0 to a value. You want to declare the function as taking a jclass**, and you want to pass &classPointer as the argument to the function; the code inside the function can then stay.


Thanks for the reply.

I changed it but it won't compile unless I change the line "*classPointer = env->GetObjectClass( obj );" to "**classPointer = env->GetObjectClass( obj );" However, when I do that, it still doesn't work. When I exit the function, the pointer is still null! What could be wrong?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I lost track of my stars. This kind of code sure does make Java look good, don't it? Anyway, this version should be right:

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Sorry, I lost track of my stars. This kind of code sure does make Java look good, don't it? Anyway, this version should be right:



Thanks, that's what I ended up doing. I appreciate the help and YES Java seems like the "cleanest" language in the world after working with C++!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!