Reputation: 134
I keep getting this error
1428460892508 :[email protected] 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
from the following code.
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();
}
}
}
}
For some reason I feel like this is extremely simple. The original code I wrote, which works, is:
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();
}
}
The original code works, however whenever I try to make it a method and insert it into the botcode, I always get errors, and when I correct them, more pop up when I try and call the trigger for !pc.babel
. Can anyone help me understand the error?
Upvotes: 1
Views: 424
Reputation: 8767
This error is key, java.lang.NoClassDefFoundError: org/jsoup/Jsoup
. That means that the Jsoup JAR is not on your applications classpath. How are you starting and running your bot? How is that different from how you start and run your original code?
Upvotes: 2