AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Delphi mit Java komunizieren

Offene Frage von "bucchi"
Ein Thema von Simon1988 · begonnen am 12. Jul 2006 · letzter Beitrag vom 27. Okt 2006
 
Simon1988

Registriert seit: 12. Jul 2006
39 Beiträge
 
#11

Re: Delphi mit Java komunizieren

  Alt 28. Jul 2006, 12:32
hey. danke .. das war echt ne super erklärung . Jetzt hab ich das verstanden denk ich .. zumindest in der Theorie. in der Praxis sieht es ganz anders aus. Hier meine procedure, die ich geschrieben hab.
Eigentlich ist es ja zum größten Teil erstmal nur abgeschrieben aber egal ..

Also ich habe in dem Order C:\Projekt Java\Delphi Code\
2 Klassen. Einmal Main.class und einmal HelloWorld.class. in die InputBox habe ich nun diesen Pfad C:\Projekt Java\Delphi Code\ angegeben

Aber bei dem Punkt //Load the VM bricht er ab. mit demm error -1

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
Var ClassPath : string;
begin
try
 JavaVM := TJavaVM.Create;
  // Set the options for the VM
    ClassPath := InputBox('JavaD','Enter the Java classpath',
    'C:\Projects\DJNI\classes');

    FillChar(Options, SizeOf(Options), #0);
    Options[0].optionString :=
    PChar('-Djava.class.path=' + ClassPath);

    VM_args.version := JNI_VERSION_1_2;
    VM_args.options := @Options;
    VM_args.nOptions := 1;
{hier bricht er ab}
      // Load the VM
    Errcode := JavaVM.LoadVM(VM_args);
    if Errcode < 0 then
    begin
      ShowMessage(Format('Error loading JavaVM, error code = %d', [Errcode]));
      Exit;
    end;

      // Create a Java environment from the JVM's Env (another wrapper class)
    JNIEnv := TJNIEnv.Create(JavaVM.Env);

      // Find the class in the file system. This is why we added
      // the current directory to the Java classpath above.
    Cls := JNIEnv.FindClass('HWJava');
    if Cls = nil then
    begin
      ShowMessage('Can''t find class: HWJava');
      Exit;
    end;

      // Find the static method 'printHello' within the HWJava class
    Mid := JNIEnv.GetStaticMethodID(Cls, 'printHello', '()V');
    if Mid = nil then
    begin
      ShowMessage('Can''t find method: printHello');
      Exit;
    end;

      // Call the static method
    JNIEnv.CallStaticVoidMethod(Cls, Mid, []);

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

end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz