I can run a class of Java project with Jpype well.
我可以成功用jpype调用标准Java工程的Class,但是我尝试调用android project的class时失败了。
Android Project代码如下,很简单的一个工程,只是打印出hello world字符串:
package real.android.test.hello;import android.app.Activity;
import android.os.Bundle;
public class hello extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}Python Jpype代码:# -*- coding: UTF8 -*-
import jpype
jvmPath = jpype.getDefaultJVMPath()
classpath = r"E:\workspace\Hello\bin\real\android\test\hello"#hello.class 所在文件夹路径
jvmArg = "-Djava.class.path=" + classpath
jpype.startJVM(jvmPath, jvmArg)
javaClass = jpype.JClass("real.android.test.hello.hello")执行python脚本错误Infomation:
Traceback (most recent call last):
File "testJpype.py", line 7, in ?
javaClass = jpype.JClass("real.android.test.hello")
File "E:\Python24\Lib\site-packages\jpype\_jclass.py", line 54, in JClass
raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.java.lang.ExceptionPyRaisable: java.lang.Exception: Class real
.android.test.hello not found.请大家帮忙,多谢!
我可以成功用jpype调用标准Java工程的Class,但是我尝试调用android project的class时失败了。
Android Project代码如下,很简单的一个工程,只是打印出hello world字符串:
package real.android.test.hello;import android.app.Activity;
import android.os.Bundle;
public class hello extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}Python Jpype代码:# -*- coding: UTF8 -*-
import jpype
jvmPath = jpype.getDefaultJVMPath()
classpath = r"E:\workspace\Hello\bin\real\android\test\hello"#hello.class 所在文件夹路径
jvmArg = "-Djava.class.path=" + classpath
jpype.startJVM(jvmPath, jvmArg)
javaClass = jpype.JClass("real.android.test.hello.hello")执行python脚本错误Infomation:
Traceback (most recent call last):
File "testJpype.py", line 7, in ?
javaClass = jpype.JClass("real.android.test.hello")
File "E:\Python24\Lib\site-packages\jpype\_jclass.py", line 54, in JClass
raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.java.lang.ExceptionPyRaisable: java.lang.Exception: Class real
.android.test.hello not found.请大家帮忙,多谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货