[英]What am I doing wrong in my PIRC bot code?
我不斷收到這個錯誤
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中時,我總是會收到錯誤,並且在糾正它們時,嘗試調用!pc.babel
的觸發器時, !pc.babel
彈出更多!pc.babel
。 誰能幫我理解錯誤?
此錯誤是鍵java.lang.NoClassDefFoundError: org/jsoup/Jsoup
。 這意味着Jsoup JAR不在您的應用程序類路徑上。 您如何啟動和運行您的機器人? 這與您啟動和運行原始代碼有何不同?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.