所以我为我的IRC机器人设置了一个INI文件,现在在.buildConfiguration()
法典:
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();
堆栈跟踪:
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)
在添加INI文件之前,它工作正常且符合预期
您的 ini.get 调用很可能返回 null。其中一个原因是,在写下所有价值观后,您永远不会ini.store()
。如果您查看此处的示例:http://ini4j.sourceforge.net/tutorial/OneMinuteTutorial.java.html 则必须在写入值后调用store()
。