def main(args: Array[String]) {
// attach to IRC if irc param is specified
if(args.contains("--irc")){
bot = new PircBotX(new Configuration.Builder()
.setName("GameNotifier")
.setNickservPassword(args(args.indexOf("--irc") + 1))
.setServerHostname("IRCSERVER")
.setServerPort(6667)
.addListener(new GameIRCListener)
.buildConfiguration())
new Thread(new Runnable { def run() { bot.startBot() }}).start()
Thread.sleep(5000)
bot.sendRaw().rawLine("JOIN " + ircChannel + " " + args(args.indexOf("--irc") + 2) + "\n")
} else run = true
如何指定irc参数并在arg中获取--irc?
编辑:
我正在使用SBT编译/打包到.jar。每当我没有--irc运行时我没有问题,但是当使用--irc运行时它会抛出以下内容
[error] (run-main-0) java.lang.ArrayIndexOutOfBoundsException: 1
java.lang.ArrayIndexOutOfBoundsException: 1
at org.trade.TraderMain$.main(TraderMain.scala:35)
at org.trade.TraderMain.main(TraderMain.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 0 s, completed Dec 24, 2015 3:07:23 AM
答案 0 :(得分:1)
你在“--irc?”旁边提供了smth,因为这一行显示你试图获取下一个参数,如果它不存在,它会抛出indexOutOfBoundException。
.setNickservPassword(args(args.indexOf("--irc") + 1))