• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

JNI - static variables vs. instance variables

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I am having a hell of a time trying to figure out why my native method can change static variables and not instance variables in a java class.
Basically I have a native method which returns a new class which holds a long value. Its how purpose in life is to hold one long variable.
The class is like this:

Now I have a method inside another class which returns a Window object with its handle;

I wanna do something like below, but it only works if I use a static variable in my Window class.

When CreateWindow is called it returns a new Window object with its handle. The problem is if I make the handle static then the handle gets passed from C to java. If I leave off the static because I would rather not have it static then the handle doesn't get passed to java from the C function.
Any help would be greatly appreciated.
Should I be so worried about using a static versus an instance variable? Does it make that much of a difference if I leave it as static?
Thanks,
Frank
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank,
It is definitely worse to access it as a static, why not make an object and access it as an instance ? I recall that I had faced the same problem and I made an object.
 
Frank Hale
Ranch Hand
Posts: 230
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I finally figured out how to access instance variables from C. I just stuff my C pointer into a Java int and then pass it back to C from Java in subsequent calls and cast it to its type. It works just like I expect it to.
I'm well on my way to a Xlib interface for Java. WooHoo!!!
If you've ever seen the Aewm window manager then I am converting it to Java using my interface, it should be pretty slick. And best of all the memory foot print has been relatively small.
Frank
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Frank, can you explain how you achieved this.
much thanks
 
Marshal
Posts: 75840
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Since the original question was last century, you might not get an answer from FH. Please explain more of what you need.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic