Thank you everyone. I think I've found my error. I think problem is
with my header file. From begining:
I wrote java code (VAJ 4.0) that uses JNI and compiled it fine.I did't
Know how to create header file from VAJ, so I' ve exported my project
from VAJ and made header file from command promt using javah -jni
command.I wrote native methods in C++ (Visual Studio 6.0). I included
java header file and I made dll successfully. In java I called
System.loadLibrary to load my dll.First I have tried to run java class
file from command line and that was successful try. When I' ve tried to
run it from VAJ I got the
NoClassDefFoundError.
Then I chaged System.loadLibrary with System.load and used absoluth
path to my dll. Now I am getting
UnsatisfiedLinkError.
I' ve searched this forum and I think I have found my error. In my
tutorial i read: "The name of the native language function that
implements the native method consists of the prefix Java_, the package
name, the class name, and the name of the native method." But I don't
have the package name in any function name in header file I' ve
created, so in my C code, even I have package. So I think it makes me
troubles. But I don't know how to fix it, because I am not familiar
with VAJ.
I hope you can understand my English and what my problem is, and would
be very thankfull for any advice.
>>Roedy Green
>>see http://mindprod.com/jgloss/cac.html
I can not open any of links that you posted in this forum?!
Gordon Beaton - 21 Nov 2005 11:47 GMT
> I' ve searched this forum and I think I have found my error. In my
> tutorial i read: "The name of the native language function that
> implements the native method consists of the prefix Java_, the package
> name, the class name, and the name of the native method."
The rule may be correct but I don't think it's complete. However
instead of trying to figure it out yourself, use javah properly and
you will get the correct names every time.
> But I don't have the package name in any function name in header
> file I' ve created, so in my C code, even I have package.
When you run javah, you must specify the fully qualified classname
(i.e. including the package name). The generated header file will show
you exactly how to declare your native methods.
E.g.:
javah my.package.MyClass
( -jni is no longer necessary )
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
ginjasvinja - 22 Nov 2005 09:11 GMT
Ok, now everything is fine with header file. When I made new header
file with package name I also executed my java class file successfully
(from command prompt). I am getting just what I've wanted, something
like this:
Some message from java before calling native....
Native message...from C
Some message fro java after calling native...
Here we go again VAJ troubles! I can't run the same code from VAJ.
Actually, I can run it and it seems like java goes fine but with no C
code executing. Result:
Some message from java before calling native....
Some message fro java after calling native...
I don't know what to do now, because I don't get any error. And I have
to use VAJ. Does anyone know what can be wrong?
Gordon Beaton - 22 Nov 2005 08:58 GMT
> Here we go again VAJ troubles! I can't run the same code from VAJ.
> Actually, I can run it and it seems like java goes fine but with no C
[quoted text clipped - 6 lines]
> I don't know what to do now, because I don't get any error. And I have
> to use VAJ. Does anyone know what can be wrong?
First, I don't know VAJ so this is just a guess...
Where should printf output (i.e. stdout) go when running from VAJ? I'm
guessing you aren't in a console. You didn't get an exception, so my
theory is that your native method *is* being called, but you just
don't see the output. Try returning a value that the caller can check
instead.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
ginjasvinja - 22 Nov 2005 10:51 GMT
Thank you Gordon, you were right. VAJ has it's own console and there I
can see java answers. Whwn I returned some string from native method to
java and print it, I could see it also. So, native method is being
called but I can't see the output.
Now I have to inform better about VAJ.
Thank you everyone!