Jump to content
  • 0

Help with code ..


Question

Posted

Hello all,

 

I've been just trying to implement one very simple voice command  on the server pack . 

 

I get no errors during compilation , but when  i run gameserver i get that error at the end.

 

I tried to trace it down but i cant find it..

 

I went on to net.sf.l2j.gameserver.handler.UserCommandHandle and line 45 but it shows no error . 

 

any help would be greatly appreciated.

 

This is the error

 

Exception in thread "main" java.lang.ExceptionInInitializerError
        at net.sf.l2j.gameserver.handler.UserCommandHandler.getInstance(UserCommandHandler.java:45)
        at net.sf.l2j.gameserver.GameServer.<init>(GameServer.java:277)
        at net.sf.l2j.gameserver.GameServer.main(GameServer.java:383)
Caused by: java.lang.NullPointerException
        at net.sf.l2j.gameserver.handler.UserCommandHandler.registerUserCommandHandler(UserCommandHandler.java:70)
        at net.sf.l2j.gameserver.handler.UserCommandHandler.<init>(UserCommandHandler.java:51)
        at net.sf.l2j.gameserver.handler.UserCommandHandler$SingletonHolder.<clinit>(UserCommandHandler.java:97)
        ... 3 more

6 answers to this question

Recommended Posts

  • 0
Posted (edited)

UserCommandHandler.java line 70 ends with a NPE. If it's your new handler, verify if you initialized it correctly.

 

Short version : UserCommandHandler instance can't load properly, because an error (NPE) has been found on line 70 during the registration of an handler.

Edited by Tryskell
  • 0
Posted
On 4/12/2019 at 4:37 PM, SweeTs said:

 

NullPointerExceptions are exceptions that occur when you try to use a reference that points to no location in memory (null) as though it were referencing an object. Calling a method on a null reference or trying to access a field of a null reference will trigger a NullPointerException

 

For example,

 

String s = null;
int len = s.length();  // NullPointerException because s is null

So you should check if the variable is null before calling any method on it, for example:

int len;
if (s == null) {
    len = 0;
}
else {
    len = s.length();  // safe, s is never null when you get here
}

 

How to avoid NullPointerExceptions?

 

  • Use the final modifier to enforce good initialization.
  • Avoid returning null in methods, for example returning empty collections when applicable.
  • Use annotations @NotNull and @Nullable
  • Fail fast and use asserts to avoid propagation of null objects through the whole application when they shouldn't be null.
  • Use equals with a known object first: if("knownObject".equals(unknownObject)
  • Prefer valueOf() over toString().
  • Use null safe StringUtils methods StringUtils.isEmpty(null).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...