JRuby与JAVA_HOME相关的错误元素类型类java.lang.String(array contains char)
我在 Ubuntu x64 位上运行:
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)
并且
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]
我在家里的 Windows 7 计算机上运行此代码。我最近将整个文件夹复制到 Ubuntu,安装了 java、jruby 和相关的 gem,但是当我运行主文件时出现此错误:
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
错误的焦点是: 测试错误错误的元素类型类 java.lang.String(array contains char)
在我的 Windows 机器上一切正常。我认为我收到此错误是因为我没有设置 JAVA_HOME 但是我将其添加到 bashrc 中:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
并已确认:
echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk
我可以通过删除 Windows 上的 JAVA_HOME 变量来产生类似的错误:
=================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
它显然不完全相同,但我有感觉这与java路径有关。您可能可以从我只是尝试使用 to_java 将 ruby 变量转换为 java 的错误中得出。这在我的 Windows 机器上运行良好,并且我已经确认宝石是相同的,但我不认为这与宝石有关。
我撒谎了。我将 JAVA_HOME 改回到 Windows 计算机上,但仍然出现此错误。所以现在代码突然无法在任何一台机器上运行。我最近在我的 Windows 机器上安装了 git 并将代码添加到存储库中。但我还没有真正用它做任何事情。它所说的只是将所有 LF 转换为 CRLF...但这不应该改变任何东西,不是吗?关于为什么我现在收到这些错误有什么想法吗?除了安装 git 之外,几个月来我没有对 Windows 机器进行任何更改。
更新:发生的事情是我无法将 ruby 字符串转换为 java 字符,即使 ruby 字符串只有 1 个字符长。这种情况以前从未发生过,而且我的 java 文件已经 2 个多月没有更新了。我也没有更新过ruby。
这是与此时的错误相关的代码行:
tokenizer = IndoEuropeanTokenizerFactory.new.tokenizer(text.split('').to_java(:char), 0, text.length)
其中文本只是被分割成每个字符的干净文本段落。类似的再现:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最新版本的 jruby(我相信是 1.5)中的 to_java 命令显然不支持将 ruby 字符串数组转换为 java 数组。如果你使用 1.3 应该可以正常工作。
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
在 jruby 9.2.9.0 中对我来说工作正常。对于 1.5,也许您必须执行
require 'java'
或其他操作。['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.