-5

I'm currently running and developing game server, but thing is i can't run it on eclipse, but i can run the server with run.bat I'm getting the error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at com.rs.ServerLauncher.main(ServerLauncher.java:75)

relevant code

public static void main(String[] args) throws Exception {
                if (args.length < 3) {
                        System.out.println("USE: guimode(boolean) debug(boolean) hosted(boolean) port(integer)");
                        return;
                }
                Settings.ECONOMY_MODE = Boolean.parseBoolean(args[2]);
                Settings.DEBUG = Boolean.parseBoolean(args[1]);
                Settings.SERVER_PORT = Integer.parseInt(args[3]); 
.....
.....
.....

complete code -My ServerLauncher class: http://pastebin.com/k1XZbqva

Thanks in advance.

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Mikk
  • 21
  • 6
  • 2
    Post code in your question so people with similar problem will be able to find this post. – Pshemo Apr 02 '15 at 10:31
  • What do you mean by "post your code in your question"? I stated that i can't post the whole class because it won't let me. I provided pastebin link with whole class – Mikk Apr 02 '15 at 10:32
  • You should post an [MCVE](http://stackoverflow.com/help/mcve) – Jens Apr 02 '15 at 10:33
  • `args.length` should be 4 if you access `args[3]` – Madhawa Priyashantha Apr 02 '15 at 10:34
  • You mean few lines of the code what represents the error? – Mikk Apr 02 '15 at 10:35
  • "I can't post the whole class because it won't let me." it won't because your code is probably too long in proportion of text you posted. As mentioned by others you should post SSCCE: short but complete code which will let us reproduce your problem. – Pshemo Apr 02 '15 at 10:36
  • @Mikk you should use `args[2]` not `args[3]` they are 0 based.you should replace x with x-1 – Madhawa Priyashantha Apr 02 '15 at 10:37
  • @FastSnail i tried, but now im getting other error: Exception in thread "main" java.lang.NumberFormatException: For input string: "false" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at com.rs.ServerLauncher.main(ServerLauncher.java:75) – Mikk Apr 02 '15 at 10:40
  • @Mikk you haven't run with correct argument .you should have code like `Settings.ECONOMY_MODE = Boolean.parseBoolean(args[1]); Settings.DEBUG = Boolean.parseBoolean(args[0]); Settings.SERVER_PORT = Integer.parseInt(args[2]);` and you should run like this `java ServerLauncher false false 1` – Madhawa Priyashantha Apr 02 '15 at 10:42

2 Answers2

1

There is your error, arrays are starting with the index 0 and not with the index 1

Settings.ECONOMY_MODE = Boolean.parseBoolean(args[2]);
Settings.DEBUG = Boolean.parseBoolean(args[1]);
Settings.SERVER_PORT = Integer.parseInt(args[3]);
SomeJavaGuy
  • 7,307
  • 2
  • 21
  • 33
0

It's like the error says, the args array does not have a fourth(args[3]) element. Remember that arrays start with index 0.

allu
  • 381
  • 1
  • 8