我在我的Eclipse项目中使用json-simple作为外部Jar。 此外部Jar 的Classpath已正确设置到.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 [...]
我无法理解为什么,我想我错过了一些东西,但我无法弄清楚 谢谢你的帮助。
答案 0 :(得分:2)
当您的应用程序在模拟器中运行时,您必须在运行时使此库可用。为此,请将json-simple-1.1.1.jar
文件放在assets/
或libs/
目录中,按the documentation。它将与您的应用程序捆绑在.apk
文件中,并且应该在运行时可用。
答案 1 :(得分:1)
假设您在Eclipse 中运行,请查看Run / Debug配置中的类路径设置。此类路径似乎与Eclipse中的常规项目/编译器类路径设置不同。