我正在使用json-simple作为外部 Jar 放入我的 Eclipse 项目中。 此外部 Jar 的类路径已正确设置到 .classpath 文件中:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
[...]
<classpathentry kind="lib" path="json-simple-1.1.1.jar"/>
[...]
</classpath>
Java 代码编译没有任何错误。
当我运行编译后的代码时,出现以下运行时错误:
Could not find class 'org.json.simple.parser.JSONParser', referenced from method [...]
我不明白为什么,我想我错过了一些东西,但我无法弄清楚。
谢谢您的帮助。
最佳答案
当您的应用程序在模拟器中运行时,您必须使该库在运行时可用。为此,请将 json-simple-1.1.1.jar
文件放入 assets/
或 libs/
目录中,按照 the documentation 。它将与您的应用程序捆绑在 .apk
文件中,并且应该在运行时可用。
关于java - Eclipse项目内的Jar运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10644582/