Thread: Loading cfg file

Results 1 to 3 of 3
  1. #1 Loading cfg file 
    Doctor p - Sweet Shop

    Join Date
    Apr 2007
    Age
    28
    Posts
    6,835
    Thanks given
    150
    Thanks received
    584
    Rep Power
    2595
    Code:
    public void loadPriceList() {
            int itemId = 0;
            BufferedReader file = null;
            String line = "", token = "", token2 = "", token2_2 = "", token3[] = new String[10];
            try {
                file = new BufferedReader(new FileReader("../Data/items/itemPrices.cfg"));
                line = file.readLine().trim();
            } catch (IOException e) {
                Misc.println("Error loading price list.");
            }
            while (line != null) {
                int spot = line.indexOf("=");
                if (spot > -1) {
                    token = line.substring(0, spot).trim();
                    token2 = line.substring(spot + 1).trim();
                    token2_2 = token2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token2_2 = token2_2.replaceAll("\t\t", "\t");
                    token3 = token2_2.split("\t");
                    if (token.equals("item")) {
                        itemId = Integer.parseInt(token3[0]);
                        itemList[itemId].minPrice = Integer.parseInt(token3[1]);
                        itemList[itemId].basicPrice = Integer.parseInt(token3[2]);
                        itemList[itemId].maxPrice = Integer.parseInt(token3[3]);
                    }
                } else {
                    if (line.contains("[")) {
                        try {
                            file.close();
                        } catch (Exception exception) {
                        }
                        file = null;
                    }
                }
                try {
                    line = file.readLine().trim();
                } catch (Exception exception1) {
                    try {
                        file.close();
                    } catch (Exception exception) {
                    }
                    file = null;
                }
            }
        }
    I get a nullpointer, because the itemId isn't read correctly, anyone knows the solution?

    example of the cfg file:
    Code:
    item = 2    178    187    196
    item = 6    123800    130300    136800
    item = 8    117000    123200    129300
    item = 10    134700    141800    148900
    item = 12    132200    139200    146100
    item = 36    18    19    20

    Reply With Quote  
     

  2. #2  
    Codex
    Rowan's Avatar
    Join Date
    Sep 2008
    Age
    25
    Posts
    1,593
    Thanks given
    0
    Thanks received
    20
    Rep Power
    1092
    check if they're all tabbed
    [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Community Veteran


    Join Date
    Dec 2008
    Posts
    4,264
    Thanks given
    405
    Thanks received
    432
    Discord
    View profile
    Rep Power
    1684
    Im thinking its because in the item prices its going like 2,6,8,10 insted of 1,2,3,4,5,6,7,8,9,10 so its not reading them right therefor not loading them.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •