Java 导入后如何在外部jar文件中使用类
我曾尝试使用导入jar文件,并尝试使用该类,但仍然不断出现错误 我用于导入jar文件的方式: 我使用eclipse作为我的java编码平台Java 导入后如何在外部jar文件中使用类,java,json,eclipse,Java,Json,Eclipse,我曾尝试使用导入jar文件,并尝试使用该类,但仍然不断出现错误 我用于导入jar文件的方式: 我使用eclipse作为我的java编码平台 import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.Arrays; public class Main { public static void main(String[] args){
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Arrays;
public class Main
{
public static void main(String[] args){
String message = "B:1:2:N";
JSONObject jsonObj = new JSONObject();
String s = message.substring(0,1);
if (s=="M"){
try {
String[] values = message.split(":");
ArrayList list = new ArrayList(Arrays.asList(values));
Object[] arr = list.toArray();
jsonObj.put("map", arr[1]); // Set the first name/pair
jsonObj.put("obstacle", arr[2]);
}
catch(JSONException ex) {
ex.printStackTrace();
}
}
if (s=="B"){
try {
String[] values = message.split(":");
ArrayList list = new ArrayList(Arrays.asList(values));
Object[] arr = list.toArray();
String Center = "("+arr[1]+", "+arr[2]+")";
String dir = "d"+arr[3];
int y;int x;
String Head = new String();
switch (dir) {
case ("dN"):
y = Integer.valueOf((String) arr[2]);
y = y+1;
Head = "("+arr[1]+", "+y+")";
case ("dW"):
x = (Integer) arr[1];
x = x-1;
Head = "("+x+", "+arr[2]+")";
case ("dE"):
x = (Integer) arr[1];
x = x+1;
Head = "("+x+", "+arr[2]+")";
case("dS"):
y = Integer.valueOf((String) arr[2]);
y = y-1;
Head = "("+arr[1]+", "+y+")";
}
//"robotHead": "(2, 1)"
//"robotCenter": "(1, 1)"
//"BOT_POS:x:y:dir"
jsonObj.put("robotHead",Head); // Set the first name/pair
jsonObj.put("robotCenter", Center);
}
catch(JSONException ex) {
ex.printStackTrace();
}
}
else{
try {
jsonObj.put("message", message);
}
catch(JSONException ex) {
ex.printStackTrace();
}
}
String M = jsonObj.toString();
System.out.print(M);
}
}
这是我一直收到的错误消息
线程“main”java.lang中出现异常。错误:未解决的编译问题:
无法将JSONObject解析为类型
无法将JSONObject解析为类型
无法将JSONException解析为类型
无法将JSONException解析为类型
无法将JSONException解析为类型
at test.MyClass.main(MyClass.java:13)
注意if(s==“B”)
不是比较Java中字符串的方式如果使用IDE(带标签的Eclipse),则需要将这些jar文件添加到构建路径“catch(JSONException ex){ex.printStackTrace();}”,在该行中,您可以尝试“catch(Exception ex)”然后你就可以看到是否还有其他问题了。@Nurhan-阅读问题。未解决的编译问题不要(只)在描述某个内容的页面上发布链接,而是解释你真正尝试过的内容——也许有人能找出哪里出了问题。否则,我们只能检查链接描述是否正确(很可能是)