本文介绍了在Jython(和Gephi)中查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Jython中使用Gephi Toolkit,但是遇到了问题.代码如下:

I'm trying to use Gephi Toolkit in Jython, but having problems with it. The code is below:

import sys
sys.path.append('gephi-toolkit.jar')
from org.openide.util import Lookup
import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(ProjectController)
workspace = pc.newProject()

print "done."

它永远不会到达最后一行.相反,会出现以下错误:

It never reaches the last line. Instead gives the following error:

Traceback (most recent call last):
  File "standalone.py", line 9, in <module>
    workspace = pc.newProject()
AttributeError: 'NoneType' object has no attribute 'newProject'

显然,"Lookup.getDefault().lookup(ProjectController)"返回无.谁能告诉我为什么?我发现以下解决方法有效(绕过了Lookup):

Apparently, "Lookup.getDefault().lookup(ProjectController)" is returning None. Can anyone tell me why? I found that the following workaround works (which bypasses Lookup):

...
import org.gephi.project.impl.ProjectControllerImpl as ProjectControllerImpl
pc = ProjectControllerImpl()
workspace = pc.newProject()

我想了解更多有关此问题的信息.谢谢.

I'd like to know more about this issue. Thanks.

推荐答案

我认为这是因为查找需要引用Java类,而不是jython包装器

i think it's because the lookup needs a reference to the java class, not the jython wrapper

尝试一下,看看它是否对您有用,至少对我来说,它返回org.gephi.project.impl.ProjectControllerImpl的实例

try this and see if it works for you,for me at least it returns an instance of org.gephi.project.impl.ProjectControllerImpl

从org.openide.util导入查找

from org.openide.util import Lookup

导入java.lang.Class

import java.lang.Class

将org.gephi.project.api.ProjectController导入为ProjectController

import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(java.lang.Class.forName("org.gephi.project.api.ProjectController"))

pc = Lookup.getDefault().lookup(java.lang.Class.forName("org.gephi.project.api.ProjectController"))

打印(pc)


set CLASSPATH =%CLASSPATH%; C:\ java \ gephi-toolkit-0.7.2014-all \ gephi-toolkit.jar

set CLASSPATH=%CLASSPATH%;C:\java\gephi-toolkit-0.7.2014-all\gephi-toolkit.jar

jython.bat gephi_test.jy

jython.bat gephi_test.jy

您应该会看到类似的东西

you should see something like

C:\ jython2.5.2> jython.bat gephi_test.jy

C:\jython2.5.2>jython.bat gephi_test.jy

org.gephi.project.impl.ProjectControllerImpl@8ddb93

org.gephi.project.impl.ProjectControllerImpl@8ddb93

这篇关于在Jython(和Gephi)中查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 06:46