[英]Trouble using java class within jruby
I'm trying to use Java Opencl from within jruby, but am encountering a problem which I can't solve, even with much google searching. 我正试图在jruby中使用Java Opencl ,但遇到了一个我无法解决的问题,即使有很多谷歌搜索。
require 'java'
require 'JOCL-0.1.7.jar'
platforms = org.jocl.cl_platform_id.new
puts platforms.class
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
when I run this code using: jruby test.rb I get the following error, when the last line is uncommented: 当我使用以下命令运行此代码时:jruby test.rb当取消注释最后一行时,我收到以下错误:
#<Class:0x10191777e>
TypeError: cannot convert instance of class org.jruby.java.proxies.ConcreteJavaP
roxy to class [Lorg.jocl.cl_platform_id;
LukeTest at test.rb:29
(root) at test.rb:4
Just wondering whether anyone has an idea on how to solve this problem? 只是想知道是否有人知道如何解决这个问题?
EDIT: ok so I think I've solved the first part of this problem by making platforms an array: 编辑:好吧所以我想通过使平台成为一个数组我已经解决了这个问题的第一部分:
platforms = org.jocl.cl_platform_id[1].new
but that led to this error when adding the next couple of lines: 但是在添加下几行时会导致此错误:
context_properties = org.jocl.cl_context_properties.new()
context_properties.addProperty(org.jocl.CL::CL_CONTEXT_PLATFORM, platforms[0])
CodegenUtils.java:98:in `human': java.lang.NullPointerException
from CodegenUtils.java:152:in `prettyParams'
from CallableSelector.java:462:in `argumentError'
from CallableSelector.java:436:in `argTypesDoNotMatch'
from RubyToJavaInvoker.java:248:in `findCallableArityTwo'
from InstanceMethodInvoker.java:66:in `call'
from CachingCallSite.java:332:in `cacheAndCall'
from CachingCallSite.java:203:in `call'
from test.rb:36:in `module__0$RUBY$LukeTest'
from test.rb:-1:in `module__0$RUBY$LukeTest'
from test.rb:4:in `__file__'
from test.rb:-1:in `load'
from Ruby.java:679:in `runScript'
from Ruby.java:672:in `runScript'
from Ruby.java:579:in `runNormally'
from Ruby.java:428:in `runFromMain'
from Main.java:278:in `doRunFromMain'
from Main.java:198:in `internalRun'
from Main.java:164:in `run'
from Main.java:148:in `run'
from Main.java:128:in `main'
for some reason when I print the class of platforms[0] it's listed as NilClass!? 出于某种原因,当我打印平台类[0]时,它被列为NilClass!?
You are overlooking a very simple mistake. 你忽视了一个非常简单的错误。 You write
你写
platforms = org.jocl.cl_platform_id.new
but that line creates a single instance of the class org.jocl.cl_platform_id
. 但该行创建了类
org.jocl.cl_platform_id
的单个实例。 You then pass that as the second parameter to org.jocl.CL.clGetPlatformIDs
in 然后,将其作为第二个参数传递给
org.jocl.CL.clGetPlatformIDs
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
and that doesn't work, because the second argument of the method requires an (empty) array of org.jocl.cl_platform_id
objects. 这不起作用,因为该方法的第二个参数需要一个
org.jocl.cl_platform_id
对象的(空) 数组 。
What the error says is: "I have something that is a proxy for a Java object and I can't turn it into an an array of org.jocl.cl_platform_id
objects, as you are asking me to do. 错误说的是:“我有一些东西是Java对象的代理,我不能把它变成一个
org.jocl.cl_platform_id
对象的数组,正如你要我做的那样。
If you just say 如果你只是说
platforms = []
and pass that in, it might just work :). 并传递它,它可能只是工作:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.