exception when creating instance of a class with native method by JNI

M

Mark_Galeck

I have another question on Java (by the way, I am writing an
application which will be a freeware/open source, so I hope this is OK
to pester the gurus here with questions)


I am trying to use JNI - I want to have a Java class Foo have a
method, that is a native C function.

I follow the Sun's tutorial

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html#examp

exactly, and everything compiles fine, and I have compiled my C .dll
as well (on Win XP). So I am ready to run - ...



Now when I finally try to run the Java application, it throws this
exception when it tries to create the Foo instance:


at Foo.<init>(Foo.java:11)
(...)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:
513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:786)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:715)
at sun.applet.AppletPanel.run(AppletPanel.java:369)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.security.AccessControlException: access denied
(java.lang.Runtim
ePermission loadLibrary.Foo)


Why would this be so??? Thank you for your insights
 
A

Andrew Thompson

Mark_Galeck wrote:

[...]
Caused by: java.security.AccessControlException: access denied

Huhh.. I had peripheral experience with loading natives in applets,
while deploying JMF and Java3D. They must have used loadLibrary,
and except for *reloading* applets (some J3D native was not
properly shut-down, and would not restart) - I had no particular
problems.
Alternatively consider using Java Web Start.

Good idea. If nothing else, deploying using JWS will allow
the deployer to supply the DLL to Windows users, and the
Shared Object to *nix. Using an applet (embedded in a web
page) would force all users to download all natives before
the applet appears on-screen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top