-2

Not sure why i get this, here is the exception:

Exception in thread "main" java.lang.NullPointerException
at org.dementhium.model.definition.ItemDefinition.loadMiscData(ItemDefinition.java:126)
at org.dementhium.model.definition.ItemDefinition.init(ItemDefinition.java:104)
at org.dementhium.model.World.load(World.java:127)
at org.dementhium.RS2ServerBootstrap.main(RS2ServerBootstrap.java:43)

here is my loadmiscdata method:

    private static void loadMiscData() throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader("data/item/poisoningitems.txt"));
    String string;
    while ((string = reader.readLine()) != null) {
        String[] data = string.split(":");
        int id = Integer.parseInt(data[0]);
        int amount = Integer.parseInt(data[1]);
        definitions[id].setPoisonAmount(amount);
    }
    reader = new BufferedReader(new FileReader("data/item/equipIds.txt"));
    while ((string = reader.readLine()) != null) {
        String[] data = string.split(":");
        int id = Integer.parseInt(data[0]);
        int equipId = Integer.parseInt(data[1]);
        definitions[id].setEquipId(equipId);
    }
}

line 126:

            definitions[id].setEquipId(equipId);

here is part of my equipids file(wont post all because its huge):

20282:5106
20284:5107
20288:5108
20290:5109
20294:5110
20296:5111
20300:5112
20302:5113
20306:5114
20308:5115
20312:5116
20314:5117
20318:5118
20320:5119
20324:5120
20326:5121
20330:5122
20332:5123
20336:5124
20338:5125
20342:5126
20344:5127

I have no idea why i am getting this exception...

Thanks in advance :)

Sorry i forgot to post definitions here it is:

private static ItemDefinition[] definitions;
definitions = new ItemDefinition[MAX_SIZE];

MAX_SIZE = 20792 btw

for the entire class look here: http://pastebin.com/rvyMp42q

Thanks again

  • 7
    Either `definitions` is null or `definitions[id]` is null. Step through your code with a debugger to figure it out. – Matt Ball Nov 29 '13 at 16:57
  • 2
    Show us the definition of `definitions` please – Blub Nov 29 '13 at 16:57
  • 2
    I'd guess either of `definitions[id]` or `equipId` is `null`. For 'better than guesses', post an [SSCCE](http://sscce.org/). – Andrew Thompson Nov 29 '13 at 16:57
  • Neither `id` nor `equipId` can be null since they're primitives (and if the data was null there should be a NumberFormatException), so I'd say it's `definitions` or `definitions[id]`. – Thomas Nov 29 '13 at 16:59
  • Set an exception breakpoint in your debugger and ye shall find the answer you seek. – biziclop Nov 29 '13 at 16:59
  • Did you actually give the array indices values? You showed the declaration, please show where you're giving the array actual `ItemDefinition` value. You need to create a `new ItemDefinition` for each index. Did you do that? – Paul Samsotha Nov 29 '13 at 17:09
  • what is value of length after `int length = buffer.getShort();` – user902383 Nov 29 '13 at 17:10
  • I added definition and i ran debugger, it says 20763:5191 broken doesn't tell me why though... – user2997839 Nov 29 '13 at 17:11
  • length after buffer.getshort = 20430 – user2997839 Nov 29 '13 at 17:15

1 Answers1

0

The Array is initialized, but the ItemDefinition at position 'id' is not initialized. It is null as of now, hence calling a setter function on it is causing a null pointer.

Try creating a new ItemDefinition

    ItemDefinition  anObj= new ItemDefinition();
    anObj.setterFunctions(...);
    definitions[id]=anObj

Hope this works.

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59