So I set up a INI file for my IRC bot made with PircBotX and now a IllegalArgumentException is thrown at .buildConfiguration()
Code:
public Craftxbot() throws IOException{
File inicheck = new File("config.ini");
if(!inicheck.exists()){
System.out.println("Configuration file not found, Making one.");
inicheck.createNewFile();
Wini ini = new Wini(new File("config.ini"));
ini.add("Config");
System.out.print("Nickname: ");
ini.put("Config", "nick", input.next());
System.out.print("Server Hostname: ");
ini.put("Config", "serverHostname", input.next());
System.out.print("Server Port: ");
ini.put("Config", "serverPort", input.nextInt());
System.out.print("Default Channel: ");
ini.put("Config", "defaultChannel", input.next());
System.out.flush();
}
Wini ini = new Wini(new File("config.ini"));
System.out.print("Nickserv Password: ");
System.out.flush();
String nickpass = input.next();
Configuration<PircBotX> alpha = new Configuration.Builder<PircBotX>()
.setName(ini.get("Config", "nick"))
.setLogin("Craftxbot-Dev")
.setNickservPassword(nickpass)
.setAutoNickChange(true)
.setServerHostname(ini.get("Config", "serverHostname"))
.setServerPort(ini.get("Config", "serverPort", int.class))
.addAutoJoinChannel(ini.get("Config", "defaultChannel"))
.addListener(new Commands())
.addListener(new EventHandler())
.addListener(new PrivMsg())
.buildConfiguration();
Stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: Must specify name
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:93)
at org.pircbotx.Configuration.<init>(Configuration.java:128)
at org.pircbotx.Configuration$Builder.buildConfiguration(Configuration.java:589)
at tk.craftxbox.bot.Craftxbot.<init>(Craftxbot.java:61)
at tk.craftxbox.bot.Craftxbot.main(Craftxbot.java:27)
Before adding the INI file it worked fine and as intended
It's likely that your ini.get calls are returning null. One reason for this is that you never
ini.store()
after writing all your values. If you look at the example here: http://ini4j.sourceforge.net/tutorial/OneMinuteTutorial.java.html you must callstore()
after writing values.