This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Bloody ACM / NetBeans

 
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the "unsatisfied link error" on a new project I created in netbeans - despite the fact that I have about three projects active that use the library. (*edit: that use the acm.jar. The projects aren't all using the same user defined library folder)


So far I've tried putting the jar file in the project folder (at the src level) and then right clicking the project > properties > libraries > add jar, and I've created (and added) an ACM library that I've added from the same properties menu. This library has been put in the main netbeans project folder in its own folder called, creatively, 'libraries'.

This may give you some more detail:



It strikes me that the problem is that because the ACM library uses no 'main' method (or more accurately the main method is within the super class 'program') replacing it with either a 'run' or 'init' method, so when I run the problem it is looking for a String or arguments that it can't find (hence the bold). Is this correct?

But more annoyingly I cannot find any logical difference between the programs that work with the acm imports. I'm sure there are differences, but I can't seem to spot them.


I'd post code, but it isn't really important - I can't even get the thing to print to the console.

Can anyone point me in roughly the right direction please? I've just spent 2 hours on this and its annoying the crap out of me!!!???

Regards,

Jeff

 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nick woodward wrote:I'm getting the "unsatisfied link error"

I'd post code, but it isn't really important


Well, that looks like the error you get when the dll containing your native code hasn't yet been loaded by the time you call it. If I'm right, then the code actually is pretty important. Can you post the smallest complete example that produces the problem? My guess is that you haven't loaded the library.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller is right, an UnsatisfiedLinkError means that you don't have a required native library (on Windows, that would be a DLL) in a place where Java can find it, or that you are using a wrong version of the DLL that is missing a specific method. The latter might be the case here, since the error message specifically refers to a particular method. Make sure you have the right version of the native library available.
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what Jesper de Jong has said is also right. That is, that a native library on Windows would be a DLL. I naïvely assumed you were using Windows when I saw the reference to DOSCommandLine, but, strictly speaking, that doesn't necessarily mean anything about what OS you are using. If you are not using Windows, then your native library probably isn't called a DLL.
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, thanks a lot guys!

Steven - I left the code out mainly because I can swap working code from one project into this one and it results in the error. Which makes me think its the way I've referenced or imported the .jar. But this makes little sense to me because the acm library has clearly been imported - and up until today I've only ever used one way (tools > libraries > add Jar). Netbeans doesn't highlight 'println()' (rather than System.out.println), 'extends ConsoleProgram' (an acm class that i'm sure you're aware of that makes 'main' unnecessary), and the 'run' method - so the acm library is accessible in some form or other.

This problem is occuring on my laptop (am on my desktop atm so don't have the specific example), if it will help though something as simple as this won't run:



which is odd because it works fine in my CS106a project, but not in my new BreakOut project, even though as far as I'm aware I imported the library in the same way.


@ Jesper de Jong - I am using windows What is confusing though is why is this occurring using the same IDE, the same root directory (c:\netbeansprojects\), the same relative directory for the library (c:\netbeansprojects\insideThisProjectFolder), and the same code and its still failing! Additionally, when this went wrong I added a custom library folder in the netbeansprojects folder to try and solve the problem. No luck either.

are there any particularly good links that talk about this topic? there seem to be many different ways to import libraries, and (apparently) many different outcomes. is there a solid method to follow when setting up a netbeans project and importing the necessary classes? clearly I haven't quite got it!!!

thanks again!





 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick, it's not enough to have the necessary libraries in proper directories. When you call a native method, it will fail unless the DLL containing that code has previously been loaded at run-time. Typically, you do that with something like this:

or this:

If a call like that is in the programs that work, but not in the one(s) that fail, simply copying the calls to the native methods from the working program to another program isn't enough. You have to load the native library with a call like one of the above, in that other program.
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stevens Miller wrote:Nick, it's not enough to have the necessary libraries in proper directories. When you call a native method, it will fail unless the DLL containing that code has previously been loaded at run-time. Typically, you do that with something like this:

or this:

If a call like that is in the programs that work, but not in the one(s) that fail, simply copying the calls to the native methods from the working program to another program isn't enough. You have to load the native library with a call like one of the above, in that other program.



wow, ok. yeah that's definitely what i was referring to when i said i 'hadn't quite got it'!!! There is definitely a huge gap in my knowledge here.

give me two seconds, I'm going to google some words everything in your post quickly!
 
Marshal
Posts: 70266
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No longer a “beginning” question. Moving.
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:No longer a “beginning” question. Moving.





somewhere in there is a compliment I guess!

OT: ok, so basically if I import a library it becomes 'native' - so you're saying that being native isn't enough, windows needs a reference to it too for every project? is that what the classpath is? i just assumed that was the library path.

I checked the properties of both projects to make sure that everything I could see was identical (even if I didn't fully understand it), and all the 'paths' it showed me were the same. Sorry, I'm a bit of a newb when it comes to this stuff.

-- having said that on the most recent restart netbeans is now complaining about a 'project problem', and the project itself has turned red (no exclamation mark). I can 'resolve' it automatically, but I'd rather improve my knowledge if you mind sparing a little more time or know of a dumbed-down link to follow!

Nick
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nick woodward wrote:if I import a library it becomes 'native'



No, that's not really it. A native method is one that has been compiled into machine-specific code. For example, some of the things I do require that I make calls to the Windows API. The way I do that is to write C++ routines that make the Windows API calls, and I compile those C++ routines into DLL files. The System.load method, called from a Java method, loads my DLL into memory. After it has been loaded, calls to methods declared "native" in my Java classes, and which have matching signatures to the routines I wrote in C++, can be called from my Java code. If I call those routines before loading the DLL files, however, the calls fail.

Now, writing those C++ routines and making them recognizable to Java is a bit tricky. But, if you already have the DLLs (because someone else wrote them and you are just using them), it's not harder to use their methods than it is to use any ordinary Java method, except that you must load the DLL at run-time before calling any of its native methods.

so you're saying that being native isn't enough, windows needs a reference to it too for every project?


Not a reference. An explicit request to load the DLL, made from your Java program, at run-time, before the methods are called

is that what the classpath is?


I'm afraid not. That's not related to what I'm describing.


I checked the properties of both projects to make sure that everything I could see was identical (even if I didn't fully understand it), and all the 'paths' it showed me were the same. Sorry, I'm a bit of a newb when it comes to this stuff.

-- having said that on the most recent restart netbeans is now complaining about a 'project problem', and the project itself has turned red (no exclamation mark). I can 'resolve' it automatically, but I'd rather improve my knowledge if you mind sparing a little more time or know of a dumbed-down link to follow!

Nick



My friend, I can tell you are trying hard, but you are in just a bit over your head here. You need to study up on "native methods." Forget about how to write them for the time being. You need to learn how to load the libraries that contain their code. There's a lot of stuff on the Web about that. It's also treated very well in Volume II of "Core Java."

Good luck.
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to have to load code that isn't native or that the JVM wouldn't understand like that makes sense. but I thought the acm package was just a collection of classes, much like the java libraries? why would you need to go outside of the java environment to load something that should be understood by the compiler.... i guess i've just got this wrong? it also still confuses me why one project would work with just the import, but this one won't. unless I unwittingly clicked 'resolve' on the other project. which i guess could've happened.

ironic that an environment created to reduce complexity often increases it unless you've a tutor or someone on hand!

thanks though, i'll look into native methods!

** edit: do you use C++ to make the API calls because its more effective?
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with the library you are using, but it's possible that it "hides" the DLL load from you, maybe in the constructor of some object you need to use the library. As I understand it, all Java implementations rely on some native code. The goal is to give you platform-independence by packing all the platform-dependent stuff into the implemtation, so you don't have to cope with it. I'm not sure it actually reduces complexity. What it does do is make certain types of errors nearly impossible to commit (such as memory leaks, but see Graphics.dispose() and decide for yourself if you feel better off ).

I use C++ to call the Windows API because that's the only way I know to make system API calls from Java. There may be others, but whenever someone suggests one, it turns out not to be able to do what I want, or is just another take on what I'm doing. Like a lot of complicated things, once you know how to use the Java Native Interface, it's easy to cobble up a native method whenever you need one. There is a respectable learning curve to it, if you need all of it. For a lot of things, the more basic aspects can do what you need. (I'd also say that, for the real-time video-processing stuff I am doing, it has some speed advantages to do things in C++, rather than copy big frames of data into the JVM, but a very nice fellow named Winston Gutkowski will make me go stand in the corner if I say that, so I won't.)
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is java particularly lacking in how it can interact with the OS then?

anyway as much as I've learnt from our discussion (a lot), I'm not sure that's the answer! netbeans is now saying that "the project uses the file/folder called "acm.jar" but this was not found.


**** Edit: ARE YOU F*£&*$£Q"^*()£"%$ kidding me.

i just placed the file in the folder (for like the 10th time today) and now its working fine. i literally think it was just netbeans/my terrible laptop being slow to recognise that i'd done what was needed. typical computer. 2/3 hours down the drain.......

thanks though. you've definitely given me a decent amount of insight into how this works,

cheers!
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck, Nick. The unloaded DLL actually is your problem, but everyone has to find their own way.
 
nick woodward
Ranch Hand
Posts: 383
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stevens Miller wrote:Good luck, Nick. The unloaded DLL actually is your problem, but everyone has to find their own way.



haha no doubt it is the dll...... given my track record of swiftly and accurately diagnosing and fixing problems i'm sure i'm wrong i definitely appreciate the help. i will keep at it!

** within 10 minutes of the GRect simple code example working, its now gone back to the same error. I don't mind that the solution is difficult, I mind that the errors or for want of a better word, symptoms, are so haphazard and inconsistent they make diagnosis difficult. oh well, back to it! again, thanks!
 
A timing clock, fuse wire, high explosives and a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic