From: jadmoka@hotmail.com (Fatme Mokaddem)
Subject: using an ada package in java (with JGnat)
Date: 1 Apr 2003 02:14:10 -0800
Date: 2003-04-01T10:14:11+00:00 [thread overview]
Message-ID: <7243325c.0304010214.ce7de23@posting.google.com> (raw)
Hello,
I have a package written in ada and I am trying to use it in a java
program. I added to the package the function to_ada_string which takes
as input a java string and returns an Ada string. This function was
provided in the examples that come with the JGnat compiler. But it's
giving me a runtime "storage_error" when I try to call it from my java
program.
Here is the code I am using:
package body A
function To_Ada_String(x : in Java.Lang.String.Ref) return String is
Bytes : Java.Byte_Arr;
begin
Bytes := Java.Lang.String.getBytes(x);
declare
Result : String(1..Bytes.all'Length);
begin
for i in Result'range loop
Result(i) := Character'Val(Bytes(Bytes.all'First+i-1));
end loop;
return Result;
end;
end To_Ada_String;
function adaMethod(input: java.Lang.String.ref) return
java.Lang.String.ref
begin
return(to_java_string(to_ada_string(input));
end adaMethod;
-- other methods...
-- ... ...
end A;
(to_java_string takes an ada string and returns a java string, and it
works fine by itself)
inside the java code, I am calling it in the following way:
String s = new String("anyString");
s = A.adaMethod(s);
I think that the main problem in is allocating space for an ada String
"Result" since when I replace "Bytes.all'Length" by a constant integer
(e.g. String(1..5) everything works fine.
Can anyone help?
reply other threads:[~2003-04-01 10:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox