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).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock