开发者

JRuby wrong element type class java.lang.String(array contains char) related to JAVA_HOME

I am on Ubuntu x64 bit running:

java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

and

jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2010-02-11 6586) (OpenJDK 64-Bit Server VM 1.6.0_18) [amd64-java]

I have this code running on my Windows 7 computer at home. I recently copied over my whole folder over to Ubuntu, installed java, jruby, and associated gems but I get this error when I run my main file:

jruby run.rb test

=================Processing FREDERICKSBURG_1.1=======================
ERROR IN TESTING wrong element type class java.lang.String(array contains char)
/home/daryl/Desktop/work/Code/geografikos/lib/sentence_splitter/splitter.rb:21:in `to_java'
/home/daryl/Desktop/work/Code/geografikos/lib/sentence_splitter/splitter.rb:21:in `split'
/home/daryl/Desktop/work/Code/geografikos/lib/models/page.rb:103:in `sentences'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/lingpipe_svm.rb:34:in `extract'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/geo_controller.rb:9:in `process'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/geo_controller.rb:8:in `each'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/geo_controller.rb:8:in `process'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/geo_controller.rb:6:in `each'
/home/daryl/Desktop/work/Code/geografikos/lib/extractor/geo_controller.rb:6:in `process'
/home/daryl/Desktop/work/Code/geografikos/lib/statistics.rb:111:in `generate_all'
/home/daryl/Desktop/work/Code/geografikos/lib/statistics.rb:105:in `each'
/home/daryl/Desktop/work/Code/geografikos/lib/statistics.rb:105:in `generate_all'
run.rb:56

The focus of the error is: ERROR IN TESTING wrong element type class java.lang.String(array contains char)

Everything works fine on my windows machine. I figured I was getting this error because I did not have JAVA_HOME set however I added this to bashrc as:

export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

and have confirmed:

echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk

I can produce a similar error by removing my JAVA_HOME variable on windows:

=================Processing FREDERICKSBURG_1.3=======================
ERROR IN TESTING cannot convert instance of class org.jruby.RubyString to char
C:/work/Code/geografikos/lib/sentence_splitter/splitter.rb:21:in `to_java'
C:/work/Code/geografikos/lib/sentence_splitter/splitter.rb:21:in `split'
C:/work/Code/geografikos/lib/models/page.rb:103:in `sentences'
C:/work/Code/geografikos/lib/extractor/lingpipe_svm.rb:34:in `extract'
C:/work/Code/geografikos/lib/extractor/geo_controller.rb:9:in `process'
C:/work/Code/geografikos/lib/extractor/geo_controller.rb:8:in `each'
C:/work/Code/geografikos/lib/extractor/geo_controller.rb:8:in `process'
C:/work/Code/geografikos/lib/extractor/geo_controller.rb:6:in `each'
C:/work/Code/geografikos/lib/extractor/geo_controller.rb:6:in `process'
C:/work/Code/geografikos/lib/statistics.rb:111:in `generate_all'
C:/work/Code/geografikos/lib/statistics.rb:105:in `each'
C:/work/Code/geografikos/lib/statistics.rb:105:in `generate_all'
run.rb:56

It is obviously not exactly the same but I have a feeling this has to do with the java path. You can probably derive from the error that I am just trying to convert a ruby variable to java using to_java. This works fine on my windows machine and I have confirmed the gems are the same but I don't think this has to do with gems.

I lied. I changed my JAVA_HOME back on my windows machine and this error still occurs. So now the code suddenly doesn't run on either machine. I recently installed git on my windows machine and added the code to a repository. But I haven't really done anything with it. All it said was it will 开发者_运维技巧convert all LF to CRLF...That shouldn't change anything though should it? Any ideas on why I am now getting these errors? I haven't changed anything on my windows machine in months except for installing git.

Update: What is going on is I cannot convert a ruby string to a java char, even if the ruby string is only 1 char long. This has never happened before and my java files have not been updated for over 2 months. I have not updated ruby either.

Here is the line of code associated with the error at this point:

tokenizer = IndoEuropeanTokenizerFactory.new.tokenizer(text.split('').to_java(:char), 0, text.length)

Where text is just a clean text paragraph being split into each character. A similar reproduction:

irb(main):002:0> ['1','2','3'].to_java :char
ArgumentError: wrong element type class java.lang.String(array contains char)
    from (irb):3:in `to_java'
    from (irb):3
irb(main):003:0> exit


Converting a ruby string array to java array apparently isn't supported with the to_java command in the latest version of jruby (1.5 I believe). If you use 1.3 it should work fine.


['1','2','3'].to_java :char works OK for me in jruby 9.2.9.0. For 1.5 maybe you have to do require 'java' or what not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜