Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Find/Debug NullPointerException without wrong line output

Newbie Spellweaver
Joined
Feb 25, 2016
Messages
5
Reaction score
0
I'm getting the following NullPointerException error in terminal:
Code:
[B]Exception during processing packet[/B]: net.sf.odinms.net.channel.handler.PlayerLoggedinHandler: null
Exception caught: java.lang.NullPointerException

How would i be able to find out the null pointer quickly in the PlayerLoggedinHandler class without a line were this happened?
The exception says during processing packet,
I can see a method called handlePacket do i have to look in this method?
And i see that MaplePacketCreator gets called alot, but this does not mean that the nullpointer exception could be in MaplePacketCreator right?
Since it clearly says net.sf.odinms.net.channel.handler.PlayerLoggedinHandler: null
 
Custom Title Activated
Loyal Member
Joined
Aug 21, 2009
Messages
1,149
Reaction score
598
That's probably because you're not printing the stack trace... just the message.

If I recall correctly, there is a class that handles the packets that are being sent by the server, your best bet would be to find the text "Exception during processing packet:" in the project, and make it print the whole stack trace so you can see where exactly this is happening.
 
Upvote 0
Custom Title Activated
Loyal Member
Joined
Jan 18, 2010
Messages
3,109
Reaction score
1,140
It means somewhere within the handlePacket of PlayerLoggedinHandler caught a NPE.

I'll assume the same thing XxОsirisxX said, you need to print the stack trace of the Exception (or Throwable even). Look into src/net/MapleServerHandler. Look for "exceptionCaught" and see where the function prints the exception cause. Call ex.printStackTrace() instead of just printing the error.

Still doesn't work? Kind of odd, but this is where you learn how to debug. Quite simple, throughout PlayerLoggedinHandler, put some println's like System.out.println("1"), System.out.println("2"), etc every 10 or so lines. The last println it prints is where the NPE caused an exception within the packet.

EDIT: To further explain a NPE, here's a quick example of what is happening:

PHP:
//In your program, you are calling to an object. For example, getUser().
public User getUser() {
    return null;//Except, something went wrong, and it's returning null! It is not returning a valid object.
}

public void handlePacket() {
    try {
        User user = getUser();
        // We decide to print their name to the console. BUT, the user returned null due to an error.
        // Because it returned null and you didn't check, we are throwing a NullPointerException.
        System.out.println(user.getName());
    } catch (Exception ex) {
        //When thrown, you can print where it happened. We commonly call printStackTrace()
        ex.printStackTrace();
    }
}

Also, MaplePacketCreator is the packets you send to the client. Normally the only time MPC ever throws a NPE is if you sent a null parameter to send in a packet.
 
Last edited:
Upvote 0
Back
Top