(For me unsolvable) array out of bounds error

Discussion in 'Plugin Development' started by Keeschaap, Nov 12, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Keeschaap

    Dear crafters,
    I'm trying to make a mapgenerator for my server, but I can't get any further because of an "java.lang.ArrayIndexOutOfBoundsException: 1"-error. Here is the code:
    Code:
    public int[][] getChunks(Server server) {
            File worldDir = server.getWorld("world").getWorldFolder();
            File regionDir = new File(worldDir, "region");
            String[] chunkFiles = regionDir.list();
            int[][] chunks = new int[chunkFiles.length - 1][2];
            int n = 0;
            chunks[1][1] = 2;
    // old one
            /*for(String chunk : chunkFiles) {
                String[] parts = chunk.split(".");
                chunks[n][0] = Integer.parseInt(parts[1]);
                chunks[n][1] = Integer.parseInt(parts[2]);
                n++;
            }*/
            for (int i = 0; i < chunkFiles.length - 1; i++) {
                String[] parts = chunkFiles[i].split(".");
                chunks[i][0] = Integer.parseInt(parts[1]);
                chunks[i][1] = Integer.parseInt(parts[2]);
            }
            System.out.println(Integer.toString(chunkFiles.length));
            return chunks;
        }
    Unfortunately, I can't figure out how to solve this one..
    Maybe one of you knows how to deal with this.

    Keeschaap
     
  2. yuour never checking if you split the size of the chunk your plit, it may be 1, and giving errors when accessing index 1
     
  3. Offline

    Panjab

    First int you used [][] ?!
     
  4. Offline

    Keeschaap

    The code isn't that clean, I tried so much xd I figured out that server.getWorld("world").getWorldFolder(); returns null.. So problem found xd
     
Thread Status:
Not open for further replies.

Share This Page