Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Problem with JNI



Permlink Replies: 4 - Last Post: May 5, 2015 6:59 PM Last Post By: Fuandi Hartanto
Fuandi Hartanto

Posts: 8
Registered: 9/22/11
Problem with JNI
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 29, 2015 8:57 PM
I tried to call java class from delphi by implementing this example from http://www.pacifier.com/~mmead/jni/delphi/JEDI/DOCS/delphi-jni-3.html

Already did as instruction, add jre to the PATH, add jni.pas to project. I have no error after compile my project. But It didn't show anything after I run the project. The only code that is written is like below. And I put it in button click event

procedure TForm1.Button1Click(Sender: TObject);
begin
try
// Create the JVM (using a wrapper class)
JavaVM := TJavaVM.Create;

except
on E : Exception do
showmessage('Error: ' + E.Message);
end;
end;

Note : I'm using delphi 2010

Edited by: Fuandi Hartanto on May 4, 2015 2:30 AM

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem with JNI [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 4, 2015 9:53 AM   in response to: Fuandi Hartanto in response to: Fuandi Hartanto
Fuandi wrote:

I tried to call java class from delphi by implementing this example
from http://www.pacifier.com/~mmead/jni/delphi/JEDI/DOCS/delphi-jni-3.html

Already did as instruction, add jre to the PATH, add jni.pas to
project. I have no error after compile my project.

But It didn't show anything after I run the project.

What are you expecting it to show? Your OnClick handler is simply creating
the JVM wrapper class, not actually initializing the JVM itself, or accessing
any Java classes afterwards. Everything described in that article about
using JNI is missing in your code example. So what is the actual problem?

--
Remy Lebeau (TeamB)
Fuandi Hartanto

Posts: 8
Registered: 9/22/11
Re: Problem with JNI [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 4, 2015 8:58 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for the reply. I created a form and a button inside, but it doesn't show. If I remark this line JavaVM := TJavaVM.Create;
My form showed to the screen and the message 'test' pop out.

I didn't put full code as in the article because this single line made my form doesn't show to the screen. Not sure what's the problem.

procedure TForm1.Button1Click(Sender: TObject);
begin
try
// Create the JVM (using a wrapper class)
JavaVM := TJavaVM.Create;

except
on E : Exception do
showmessage('Error: ' + E.Message);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
showmessage('test');
end;

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem with JNI [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2015 6:22 PM   in response to: Fuandi Hartanto in response to: Fuandi Hartanto
Fuandi wrote:

Thanks for the reply. I created a form and a button inside, but it
doesn't show. If I remark this line JavaVM := TJavaVM.Create;

My form showed to the screen and the message 'test' pop out.

There is no way your OnClick code can be interferring with your call to ShowMessage(),
since OnShow is called before OnClick.

I didn't put full code as in the article because this single line made
my form doesn't show to the screen.

There is no possible way that a TJavaVM failure inside of an OnClick handler
would prevent the Form from showing. Something else is going on. Makes
me think this is not your real code, or even an accurate representation of
your real code.

--
Remy Lebeau (TeamB)
Fuandi Hartanto

Posts: 8
Registered: 9/22/11
Re: Problem with JNI [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 5, 2015 6:59 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
That's why I'm asking, because I also don't know why my form won't show.
I'm using delphi 2010. Below is my source code. I only have 1 unit inside the project

I also put the project files here
https://www.dropbox.com/s/460amu5zw0e6w3n/Delphi.zip?dl=0


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, JNI, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Options: array [0..4] of JavaVMOption;
VM_args: JavaVMInitArgs;
JavaVM: TJavaVM;
JNIEnv: TJNIEnv;
Cls: JClass;
Mid: JMethodID;
Errcode: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
try
// Create the JVM (using a wrapper class)
JavaVM := TJavaVM.Create;

except
on E : Exception do
showmessage('Error: ' + E.Message);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
showmessage('test');
end;

end.

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02