Random null pointer exception


#1

As shown in the photo “sorry couldn’t upload it here maximum size is 50kb” this random null pointer happens and after I ignore it and start again it works normally and then it happens randomly or I think when I change something in the scene.
The java line he is referring to is ‘" assetManager.loadModel(“Scenes/backup2_1.j3o”) "’


#2

one tip: try upload to hosts like https://imgur.com/ or any other that is filtered via forum and opened via it. some people dont like unknown links. this one sounds popular, but i dont know it.


#3

Alright thank you I will try to change the photo source.


#4

I’ve fixed it for you. You just needed to use a direct link to the image and add an extension for it to work.


#5

Thanks <3

Doesn’t anyone know the solution for this?


#6

We would need to at least see some code…


#7

There’s no such thing as a “random null pointer exception”. Every NPE generates a stack trace which provides valuable clues as to the root cause. In this case, the stack trace is provided by the screenshot. It points to line 314 in BinaryImporter.java . The screenshot also indicates that the SDK version is 3.2.2-stable-sdk1. Assuming the Engine version matches the SDK, that points to the following line of code:

int loc = locationTable.get(id);

If it’s really that line of code, the only reasonable interpretation would be that locationTable is null. Here’s the context:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/v3.2.2-stable/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java


#8

you sure? looking at code, it just can’t be null.

but it assign to int not Integer, while result of get can be null;

about reason, idk, would need to have object(model that cause issue) and just debug variables.


#9

Maybe set a breakpoint in Multiplayer.java at line 86 and see if anything is wrong at that point in time?


#10

yes, this also. but anyway its task for @hossam_ahmed. i dont even know if Multiplayer.java is his class or JME one.(because its not in jme3 package).

first i thought its some sdk issue, but noticed now its run.


#11

That is not the only reasonable explanation.

locationTable.get() is returning a BIG i integer. java.lang.Integer… which can be null.

But it is being auto-unboxed to LITTLE i integer: int. This can throw an NPE if the result of the get() is null.

Which rereading, was already stated here though I did not get that from the first read.

So the question then comes: why are you randomly reading j3o objects during your game run and can you just capture the exception and print which model is causing the issue?


#12

@pspeed i felt like your last question was directed to me :sweat_smile: because i dont get it. author said its ‘" assetManager.loadModel(“Scenes/backup2_1.j3o”) "’


#13

No, it was directed at OP because I somehow missed his mentioning of the file.

…I still wonder why he is randomly loading that same file all the time and why it is somehow bypassing the cache.

Anyway, it seems that file is corrupt.