我一直收到此错误
1428460892508 :Monstarules!webchat@ool-43563441.dyn.optonline.net PRIVMSG #botte
ster :!pc.babel
1428460892510 ### Your implementation of PircBot is faulty and you have
1428460892510 ### allowed an uncaught Exception or Error to propagate in your
1428460892511 ### code. It may be possible for PircBot to continue operating
1428460892511 ### normally. Here is the stack trace that was produced: -
1428460892511 ###
1428460892511 ### java.lang.NoClassDefFoundError: org/jsoup/Jsoup
1428460892512 ### at MyBot.onMessage(MyBot.java:20)
1428460892512 ### at org.jibble.pircbot.PircBot.handleLine(PircBot.java:99
0)
1428460892512 ### at org.jibble.pircbot.InputThread.run(InputThread.java:9
2)
1428460892512 ### Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
1428460892513 ### at java.net.URLClassLoader.findClass(URLClassLoader.java
:381)
1428460892513 ### at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
1428460892513 ### at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.j
ava:331)
1428460892514 ### at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
1428460892514 ### ... 3 more
来自以下代码。
import org.jibble.pircbot.*;
import org.jsoup.*;
import org.jsoup.helper.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
import java.io.*;
public class MyBot extends PircBot {
public MyBot() {
this.setName("^MonstaBot^");
}
public void onMessage(String channel, String sender, String login, String hostname, String message) {
if(sender.equalsIgnoreCase("monstarules") && message.equalsIgnoreCase("!quit")){
quitServer("Good bye!");
}
if(message.equalsIgnoreCase("!pc.babel")) {
String playerList = new String();
Document doc = null;
try {
doc = Jsoup.connect("http://aos075.aloha.pk:34886/").get();
String text = doc.html();
FileWriter fw = new FileWriter("temp1.txt");
fw.write(text);
fw.close();
BufferedReader br = new BufferedReader(new FileReader("temp1.txt"));
for(int i = 0; i < 103; ++i)
br.readLine();
text = br.readLine();
text = text.trim();
text = text.replaceAll("<br>", "").replaceAll("<p>", "").replaceAll("</p>", "");
text = text.replace("Hello! Welcome to the status server for aloha.pk tower of babel. ", "");
int stlg = text.length() - 1;
for(int i = (stlg - 22); stlg > i; i++) {
String tw = "" + text.charAt(i);
playerList = playerList + tw;
}
sendMessage(channel, playerList);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
出于某种原因,我觉得这非常简单。我编写的原始代码是:
import java.io.*;
import org.jsoup.*;
import org.jsoup.helper.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
public class Scraper {
public static void derp() throws IOException {
String playerList = new String();
Document doc = null;
try {
doc = Jsoup.connect("http://aos075.aloha.pk:34886/").get();
}
catch (IOException e) {
e.printStackTrace();
}
String text = doc.html();
FileWriter fw = new FileWriter("temp1.txt");
fw.write(text);
fw.close();
BufferedReader br = new BufferedReader(new FileReader("temp1.txt"));
for(int i = 0; i < 103; ++i)
br.readLine();
text = br.readLine();
text = text.trim();
text = text.replaceAll("<br>", "").replaceAll("<p>", "").replaceAll("</p>", "");
text = text.replace("Hello! Welcome to the status server for aloha.pk tower of babel. ", "");
int stlg = text.length() - 1;
for(int i = (stlg - 22); stlg > i; i++) {
String tw = "" + text.charAt(i);
playerList = playerList + tw;
}
System.out.print(playerList);
}
public static void main(String[] args) throws IOException {
derp();
}
}
原始代码有效,但每当我尝试将其作为方法并将其插入到botcode中时,我总会得到错误,当我更正错误时,当我尝试调用{{1}的触发器时会弹出更多错误}。任何人都可以帮我理解错误吗?
答案 0 :(得分:2)
此错误是关键,java.lang.NoClassDefFoundError: org/jsoup/Jsoup
。这意味着Jsoup JAR不在您的应用程序类路径上。你是如何开始和运行你的机器人的?与开始和运行原始代码的方式有何不同?