gpt4 book ai didi

java - 从 Map 实例化 JSONObject 时出错 : java. lang.NoSuchMethodError

转载 作者:行者123 更新时间:2023-12-01 11:04:46 24 4
gpt4 key购买 nike

我在 Java 中使用 JSONObject 时遇到错误。

我正在尝试从 Map 实例化 JSONObject:

Collection<Faction> factions = FactionColl.get().getAll();

for(Faction f : factions) {
String fac_id = f.getId();

ResultSet count = this.db.query("SELECT COUNT(*) AS count FROM helu_fac WHERE fac_id='" + fac_id + "'");
int exist = 0;
while(count.next()) {
exist = count.getInt("count");
}

if(exist == 0) {
Connection conn = this.db.getConnection();
PreparedStatement statement = conn.prepareStatement("INSERT INTO helu_fac VALUES(?,?,?,?,?,?,?)");
statement.setInt(1, 0);
statement.setString(2, fac_id);
statement.setString(3, f.getName().toLowerCase());
statement.setString(4, f.getDescription());
statement.setString(5, new JSONObject(f.getRelationWishes()).toJSONString());
statement.setDouble(6, f.getPower());
statement.setInt(7, 1);

statement.executeUpdate();
conn.close();
} else {

Connection conn = this.db.getConnection();
PreparedStatement ps = conn.prepareStatement(
"UPDATE helu_fac SET "
+ "fac_id = ?,"
+ "name = ?,"
+ "description = ?,"
+ "relations = ?,"
+ "power = ?"
+ " WHERE fac_id = \"" + fac_id +"\"");
ps.setString(1, f.getId());
ps.setString(2, f.getName().toLowerCase());
ps.setString(3, f.getDescription());
ps.setString(4, new JSONObject(f.getRelationWishes()).toJSONString());
ps.setString(5, String.valueOf(f.getPower()));

ps.executeUpdate();

conn.close();
}

}

我收到以下错误:

java.lang.NoSuchMethodError: org.json.simple.JSONObject: method <init>(Ljava/util/Map;)V not found

我到处搜索,但仍然收到此错误。

感谢您的帮助!

最佳答案

正如错误告诉您的那样,org.json.simple.JSONObject 没有接受 Map 作为唯一参数的构造函数。

也许您打算使用 org.json.JSONObject,它确实有这样的构造函数?

检查您在类顶部导入了哪个 JSONObject

关于java - 从 Map 实例化 JSONObject 时出错 : java. lang.NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33066631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com