英文:
python pyjnius; PythonActivity error I installed JDK+Visual C++
问题
我已安装了JDK和Visual Studio。我可以无问题地导入其他类,但在导入PythonActivity类时一直出现错误。
我正在使用javac 14.0.2和C++
我的代码:
import kivy
from kivy.app import App
from kivy.uix.label import Label
from jnius import autoclass
PythonActivity = autoclass('org.kivy.android.PythonActivity')
class MyApp(App):
def build(self):
return Label(text=str(type(PythonActivity)))
if __name__ == "__main__":
MyApp().run()
错误信息:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
File "D:\DNDR\Yeni klasör\lib\site-packages\jnius\reflect.py", line 229, in autoclass
c = find_javaclass(clsname)
File "jnius\jnius_export_func.pxi", line 26, in jnius.find_javaclass
File "jnius\jnius_utils.pxi", line 91, in jnius.check_exception
jnius.JavaException: JVM exception occurred: org/kivy/android/PythonActivity java.lang.NoClassDefFoundError
英文:
I installed JDK and Visual Studio. I can import other classes without any problem, but I keep getting errors while importing the PythonActivity class.
I am using javac 14.0.2 and C++
my codes:
import kivy
from kivy.app import App
from kivy.uix.label import Label
from jnius import autoclass
PythonActivity = autoclass('org.kivy.android.PythonActivity')
class MyApp(App):
def build(self):
return Label(text=str(type(PythonActivity)))
if __name__=="__main__":
MyApp().run()
and errors:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
File "D:\DNDR\Yeni klasör\lib\site-packages\jnius\reflect.py", line 229, in autoclass
c = find_javaclass(clsname)
File "jnius\jnius_export_func.pxi", line 26, in jnius.find_javaclass
File "jnius\jnius_utils.pxi", line 91, in jnius.check_exception
jnius.JavaException: JVM exception occurred: org/kivy/android/PythonActivity java.lang.NoClassDefFoundError
答案1
得分: 0
以下是翻译好的内容:
该活动是为 Android 应用程序创建的,因此在这种情况下,pyjnius 将被用于访问 Android 应用程序的类。您只需编写、编译并在 Android 上运行代码。这个活动属于 Android 应用程序。Buildozer 或 p4a 创建活动文件。因此,请尝试使用 p4a 或 buildozer 进行构建,然后在 Android 模拟器或设备上运行,然后检查日志。
我在我的项目中使用了这个。我使用 buildozer 构建了 APK。该应用程序运行良好。
链接:
- https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L46
- https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L670
- https://stackoverflow.com/questions/23546283/installing-pyjnius-on-windows
英文:
The activity is created for android app, so in this case pyjnius will be used android app to access class. You have to just code, compile and run on Android. The activity is of android app. The buildozer or p4a create activity file. So try building using p4a or buildozer and then run on Android emulator or device and then check for log.
I have used this in my project. I have l build apk using buildozer. The app works fine.
https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L46
https://github.com/infinyte7/Mandarin-News-Feed/blob/master/Mandarin%20News%20Feed/main.py#L670
https://stackoverflow.com/questions/23546283/installing-pyjnius-on-windows
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论