在我最新的項目中,我使用JSoup來檢索一個網頁,獲取所有帶有「.heads」類的元素,然後將它的特定部分保存到一個文件中。當我運行它,我得到這個錯誤:Weird java.lang.ExceptionInInitializerError - JSoup
java.lang.ExceptionInInitializerError
at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:19) ~[?:?]
at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:373) ~[?:?]
at org.jsoup.nodes.Document.<init>(Document.java:18) ~[?:?]
at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:29) ~[?:?]
at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:42) ~[?:?]
at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:53) ~[?:?]
at org.jsoup.parser.Parser.parseInput(Parser.java:30) ~[?:?]
at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:94) ~[?:?]
at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:603) ~[?:?]
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:195) ~[?:?]
at de.zbs.advancedheads.main.AdvancedHeads.downloadDatabase(AdvancedHeads.java:48) ~[?:?]
at de.zbs.advancedheads.main.AdvancedHeads.onEnable(AdvancedHeads.java:33) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-fdc1440-53fac9f]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source) ~[?:1.8.0_73]
at java.util.Properties.load0(Unknown Source) ~[?:1.8.0_73]
at java.util.Properties.load(Unknown Source) ~[?:1.8.0_73]
at org.jsoup.nodes.Entities.loadEntities(Entities.java:236) ~[?:?]
at org.jsoup.nodes.Entities.<clinit>(Entities.java:220) ~[?:?]
... 28 more
我的代碼如下:
private boolean downloadDatabase() {
new File(path).mkdirs();
try {
Document doc = Jsoup.connect("http://heads.freshcoal.com/maincollection.php").get();
Elements head = doc.select(".heads");
System.out.println(head);
for (Element e : head) {
Attributes att = e.attributes();
System.out.println(att);
String command = att.get("data-clipboard-text");
System.out.println(command);
String remover = command.replace("/give @p skull 1 3 {display:{Name:\"", "");
String name = remover.substring(0, 5);
Bukkit.broadcastMessage(name);
String texture = remover.substring(30, 50);
Bukkit.broadcastMessage(texture);
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
是的,我已經籤羯羊安裝jsoup庫,我不知道怎麼做它是一個圖書館,所以我只是把它的來源,並把它放到我的項目。
感謝您提前提供任何幫助!
哪一行給出錯誤 – Abdelhak
看起來像是應該在JSoup中嵌入的'entities-base.properties'文件存在問題...... –
看起來像添加源碼不能解決庫問題.. 。我正在使用eclipse,將.jar添加到「構建路徑」並在'export'和'導出順序'上勾選了checkebox。仍然得到一個'java.lang.NoClassDefFoundError:org/jsoup/Jsoup' – TheLexoPlexx