skadistats / clarity-examples

Example code for clarity
BSD 3-Clause "New" or "Revised" License
113 stars 37 forks source link

get java.lang.reflect.InvocationTargetException when try to get getDtClass() of an entity #41

Closed vbashiri closed 4 years ago

vbashiri commented 4 years ago

I try to get property value of an ability and get this error in runtime. I'v gon entity by its handler from Hero's entity. ctx.getProcessor(Entities.class).getByHandle((int) getEntityProperty(e, handlerName,null));

then when I try to getDtClass I'v got this error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.simontuffs.onejar.Boot.run(Boot.java:340)
        at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.NullPointerException
        at skadistats.clarity.examples.combatlog.Main.onUpdated(Main.java:124)
        at skadistats.clarity.event.AbstractInvocationPoint.invoke(AbstractInvocationPoint.java:86)
        at skadistats.clarity.event.Event.raise(Event.java:37)
        at skadistats.clarity.processor.entities.Entities.lambda$emitUpdatedEvent$4(Entities.java:539)
        at java.util.ArrayList.forEach(Unknown Source)
        at skadistats.clarity.processor.entities.Entities.onPacketEntities(Entities.java:357)
        at skadistats.clarity.event.AbstractInvocationPoint.invoke(AbstractInvocationPoint.java:86)
        at skadistats.clarity.event.Event.raise(Event.java:37)
        at skadistats.clarity.processor.reader.InputSourceProcessor.processEmbedded(InputSourceProcessor.java:247)
        at skadistats.clarity.event.AbstractInvocationPoint.invoke(AbstractInvocationPoint.java:86)
        at skadistats.clarity.event.Event.raise(Event.java:37)
        at skadistats.clarity.processor.reader.InputSourceProcessor.processSource(InputSourceProcessor.java:174)
        at skadistats.clarity.event.AbstractInvocationPoint.invoke(AbstractInvocationPoint.java:86)
        at skadistats.clarity.event.Event.raise(Event.java:37)
        at skadistats.clarity.processor.runner.AbstractFileRunner.initAndRunWith(AbstractFileRunner.java:39)
        at skadistats.clarity.processor.runner.SimpleRunner.runWith(SimpleRunner.java:33)
        at skadistats.clarity.examples.combatlog.Main.run(Main.java:240)
        at skadistats.clarity.examples.combatlog.Main.main(Main.java:247)
        ... 6 more

when I log the entity, It's fine and I can see the properties and their values.

Where did I go wrong?

spheenik commented 4 years ago

Hmm, the error is in your code at skadistats.clarity.examples.combatlog.Main.onUpdated(Main.java:124)

What exactly is null?

vbashiri commented 4 years ago

yeah, Line 124: log.info("--->, {}", abilities_00.getDtClass());

I am new to java and specially maven and I dont know how use debug mode. :( but as I siad when I try to getDtClass I got this error.

spheenik commented 4 years ago

Then I guess that abilities_00 is null.

vbashiri commented 4 years ago

I try to log abilities_00 before that line and now I don't get any error. sorry and thanks. :)))

spheenik commented 4 years ago

I am new to java and specially maven and I dont know how use debug mode. :(

I recommend using a decent IDE (I personally use Intellij Idea), handling maven projects and debugging is very easy to do in there.

vbashiri commented 4 years ago

update here: The problem was abilities and items can be null sometimes. I should handle that. thanks anyway. :D

spheenik commented 4 years ago

There is a concept of an empty handle. Is is game specific what the empty handle is, but you can get it by doing ctx->getEngineType()->emptyHandle(). You can then compare the handles, and if yours matches the empty handle, you will always get null. You should never get null back for a handle that is not the empty handle.

vbashiri commented 4 years ago

I didn't know that. In source 2 it is 16777215. I will use this. Tnx.