Jason, Although the idea is good, what your trying to do can't work. And when you think about it it's actually really simple.
Suppose you call a Java method (from Perl) that returns a String. What does Inline::Java do with the String? It nicely converts it to a Perl scalar for you and allows you to forget all about the String object. Unfortunately that exactly what is happening here also :( There is indeed a bug here because the error is not being caught (I will add a croak in this case), but basically it boils down to the fact that java.lang.String objects simply can't live in Perl since they are magically transformed into Perl scalars. But you can easily work around this by creating a wrapper method like such: use strict; use warnings; use Inline ( Java => 'DATA', ) ; foreach my $b (@{StringOps->getBytes("Test Me")}){ print "$b\n" ; } __DATA__ __Java__ class StringOps { static public byte [] getBytes(String s){ return s.getBytes() ; } } Cheers, Patrick On 9/16/05, Jason Stelzer <[EMAIL PROTECTED]> wrote: > Hello, I've been using Inline::Java to do some integration work. Its > been quite successful over all. However, I've come upon a simple task > that I'm either going about completely the wrong way, or I've found a > minor problem. > > The short version is I want to convert a perl string into a java byte[] > array. I was planning on using java.lang.String and calling getBytes. > The strings are fairly short, so it should be fine. However, that > doesn't work. In fact, I can't seem to get any methods on a > java.lang.String object to work. I consistently get a > java.lang.NumberFormatException. > > Running the following code: > use strict; > use warnings; > use Inline ( > Java => 'STUDY', > STUDY => [], > ) ; > use Inline::Java qw(study_classes) ; > > study_classes(['java.lang.String'], undef) ; > print "imported classes\n"; > my $str = java::lang::String->new("Test me") ; > print "Created string obj\n"; > print($str->length . "\n") ; > > Produces the following results: > imported classes > Created string obj > Exception in thread "IJST-#0" java.lang.NumberFormatException: For input > string: "java.lang.String" > at > java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) > at java.lang.Integer.parseInt(Integer.java:447) > at java.lang.Integer.parseInt(Integer.java:497) > at > org.perl.inline.java.InlineJavaProtocol.CallJavaMethod(InlineJavaProtocol.java:240) > at > org.perl.inline.java.InlineJavaProtocol.Do(InlineJavaProtocol.java:38) > at > org.perl.inline.java.InlineJavaServer.ProcessCommand(InlineJavaServer.java:136) > at > org.perl.inline.java.InlineJavaServer.ProcessCommand(InlineJavaServer.java:125) > at > org.perl.inline.java.InlineJavaServerThread.run(InlineJavaServerThread.java:51) > Can't receive packet from JVM: > at > /home/jstelzer/projects/datapump/dp_build/hms/datapump/ext/lib/perl5/site_perl/5.8.6/i686-linux/Inline/Java/Protocol.pm > line 337 > at string.pl line 14 > > > I'm in the process of reading the code, but I was wondering if this is > just a fundamentally flawed way of getting what I need? > > TIA > > -- > J. > > -- ===================== Patrick LeBoutillier Laval, Québec, Canada