【问题标题】:External jar cannot be resolved in eclipse in Ubuntu在 Ubuntu 的 eclipse 中无法解析外部 jar
【发布时间】:2012-07-25 07:30:46
【问题描述】:

我用java写了一个简单的JsonParser代码。我在this post 之后下载了 json jar 文件。我通过包含jar文件,

Project Properties-> Java Build Path -> Libraries -> Add external jars  

但对于导入语句,我仍然收到错误“无法解析导入 org.json.JSONObject”。

这发生在我的 Ubuntu 机器上。但是按照相同的步骤,我可以成功地包含 jar 并在 Windows 中运行我的程序。但我希望它在我的 Ubuntu 机器上工作。我应该做点不同的事情吗?

我的项目目录中有 jar 文件。它也被列在 Package explorer 中的 Referenced Libraries 下。

[编辑]: 我做了一个 ctrl + shift + O 来组织eclipse中的导入和语句

import org.json.JSONObject
import org.json.JSONArray
import org.json.JSONExceptiop

改成,

import org.json.simple.JSONObject
import org.json.simple.JSONArray

出现以下错误,

The constructor JSONArray(String) is undefined
The method length() is undefined for the type JSONArray
The method getJSONObject(int) is undefined for the type JSONArray

【问题讨论】:

    标签: eclipse json ubuntu import jar


    【解决方案1】:

    看起来你从这里下载了 .jar:

    http://code.google.com/p/json-simple/

    而您的导入是基于此处的 .jar:

    http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip

    来自 json-simple 的 JSONArray 没有采用单个字符串的构造函数。切换 .jar 文件或修复构造函数。

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 2017-09-30
      相关资源
      最近更新 更多