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.

Reply via email to