Jump to content
  • 0

NPE are boring :/


Tryskell

Question

Hi all,

 

as I have lost my pack (L2J archid) forum account (I still wait for ya Sethek :P), I post here, as it can help more people, and it's not a relative question to L2Jarchid, but java in general.

 

NPE... For NullPointerException. I got a lot of those errors, for many different things.

 

- my voicedcommandhandlers bug cause of that ;

- sieges doors make this error, but work ;

-throne siege is buggy too, when i try to sit on it i got an NPE.

 

So I would like to ask : what are those errors, and how I can fix it. I ask for theory, and perhaps if u got an existing exemple to show (from any pack, I don't care) it would be cute.

 

I got a really lil idea about it ; I think it's an exception which come when something is null. But got no idea if I have to set a variable for that, etc.

 

Those errors seem to occur when I double click, or more accuratly, when I already made that action one time.

 

For example, castle doors ; one click on any door and i can still move. If I click on one door, and click one time on another door, no error too. But if I double click on any gate, I got NPE error, and my character is "stuck" until I click on me.

 

About my voicecommand, it's more drama as it bugs the entire command : when you type .stats you got stats (shared on this forum :P), it's bug differently according if i'm an admin or no. I didn't understand how, but it happens and block the command (only show one NPE error w/o show something anymore) until a client restart...

 

I "coded" this voicecommandhandler 3 times, 3 differents ways (using or no the npchtmlmessage, and reading sources from L2j interlude, l2jfree interlude, and l2jumbrella gracia 1.5). I don't understand, cause my voicecommander is P.E.R.F.E.C.T and it makes me cry to see I spend so much time on a stupid NPE error lol.

 

Well, any point of view can help... If you need screenshots of errors, just tell me.

 

Exception in thread Normal packet Pool xx
java.lang.NullPointerException
at ihateNPE.gamerserver.network.clientpackets.L2GameClientPacket.run

 

(xx = number of the error, it goes ++ each time...)

And no I didn't mod L2gameclientpacket... And ofc, it's not ihateNPE :p.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

npe = NullPointerException you get it when a non-null value returns null ^^ ( means a value or a variable not definited right is null )

Well when u call a class or request smth thats not definited its gonna be null. thats why u must use constructors or make sure u defined right ur mrthods..

Also a way to avoid nps are try & catch suroundings or null checks (e.g if(_playerMap != null) or if(_playerMap == null)return;).

 

If u need more help tell us.. and like intrepid sayd, post here one of ur codes that get npe's often.

@Tryskell i cant find your acc in the db.. you gotta create it again.. im guessing u made your acc when we did a roll back :-s

 

Link to comment
Share on other sites

  • 0

Ty for support, but the problem is i already got a null verification....

 

package com.l2jarchid.gameserver.handler.voicedcommandhandlers;

import javolution.text.TextBuilder;

import com.l2jarchid.gameserver.handler.IVoicedCommandHandler;
import com.l2jarchid.gameserver.model.actor.instance.L2PcInstance;
import com.l2jarchid.gameserver.network.serverpackets.NpcHtmlMessage;

public class faction implements IVoicedCommandHandler
{
   private static final String[] VOICED_COMMANDS = { "faction" };

   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
   {   
   	if (command.equalsIgnoreCase("faction"))
       {          
   		if (activeChar.getTarget()==null || (!(activeChar.getTarget() instanceof L2PcInstance)))
   		{
   			activeChar.sendMessage("Incorrect target.");
   			return true;
   		}
   		
           L2PcInstance targetp = (L2PcInstance)activeChar.getTarget();
           
           TextBuilder htmlContent = new TextBuilder("<html><title>Character stats</title><body><center>");
           htmlContent.append("<br><font color=\"00FF00\">=========>>"+ targetp.getName() +"<<=========</font><br>");
           htmlContent.append("<font color=\"FF0000\">Level:</font> " + targetp.getLevel()+"<br>");
           htmlContent.append("<font color=\"FF0000\">Clan:</font> " + targetp.getClan().getName()+" | ");
           htmlContent.append("<font color=\"FF0000\">Alliance:</font> " + targetp.getClan().getAllyName()+"<br>");
           htmlContent.append("<font color=\"FF0000\">Adena:</font> " + targetp.getAdena()+"<br>");
           htmlContent.append("<font color=\"FF0000\">PvP Kills:</font> " + targetp.getPvpKills()+" | ");
           htmlContent.append("<font color=\"FF0000\">Number of Deaths:</font> " + targetp.getPkKills()+"<br>");
           		
           htmlContent.append("<font color=\"00FF00\">=========>> Faction related <<========="+"</font><br>");
           htmlContent.append("<font color=\"FF0000\">Faction points:</font> " + targetp.getFactionPoints()+"<br>");
           htmlContent.append("</center></body></html>");
           
           NpcHtmlMessage faction = new NpcHtmlMessage(0);
           faction.setHtml(htmlContent.toString());
           activeChar.sendPacket(faction);
       }
      return true;
   }
   public String[] getVoicedCommandList()
   {
       return VOICED_COMMANDS;
   }

}

 

Error :

 

http://img696.imageshack.us/img696/1455/sanstitre1em.jpg

 

I must add it's a faction server, even if it's not a useful info. The strange thing is from the actual c/p code, a factioned ppl when he target himself got this error. When I do with admin, it works on me, never error. Until I try on another char...

 

And as Intrepid like, it's "shitlude" :p. But voicedcommand is 98% the same than any new l2j release so... Tell me if you find something strange... About the imbricated verification ( || ), I already tested even desimbricated, and with/without the second verification (which see if it's a character or no, right ?).

 

About faction points, yeah it's working well, no problem about it.

 

If all NPE points to the same file, you think it can come from L2GameClientPacket ? Or it's just because it's a packet which bug, and as it's the normal way of the packet, it bugs when it tries to receive/send ?

 

Sethek, as it's your "baby", you should perhaps know. I checked the code, and what is opcode, I find more than 800 things about it :P. And this file is a mix between l2j interlude and nowadays l2j (i mean the packet weight check, between 12 and 100). Np about my forum account, what is it strange, is I saw me in members, and "Tryskell" was already taken so :P.

 

I tested both "True" and "False" return, without any visible effect... Both are on True, I saw it on another command, which is strange...

 

About

new NpcHtmlMessage(0)

, what exactly is the 0 ? I saw both 0 or 5... Dunno why... And seems to bug the same way :D.

 

About Archid forum...

 

sanstitre1qtp.th.jpg

 

So what ? I create another account ? :P

 

Link to comment
Share on other sites

  • 0

if (activeChar.getTarget()==null || (!(activeChar.getTarget() instanceof L2PcInstance)))

Lol... think of simple codes take a look in my code:P

 

activeChar.getTarget() == null = Means if activeChar is null

!(activeChar.getTarget() instanceof L2PcInstance) = if activeChar is not a instance of L2PcInstance.. and heres a null value cus the target can be null cus ur method had || means OR

.... && means and... guess u get the picture ^^

 

package com.l2jarchid.gameserver.handler.voicedcommandhandlers;

import javolution.text.TextBuilder;

import com.l2jarchid.gameserver.handler.IVoicedCommandHandler;
import com.l2jarchid.gameserver.model.actor.instance.L2PcInstance;
import com.l2jarchid.gameserver.network.serverpackets.NpcHtmlMessage;

public class faction implements IVoicedCommandHandler
{
   private static final String[] VOICED_COMMANDS = { "faction" };

   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
   {   
   	if (command.equalsIgnoreCase("faction"))
       {          
           L2PcInstance targetp = (L2PcInstance)activeChar.getTarget();

           if(targetp != null)
           {
           TextBuilder htmlContent = new TextBuilder("<html><title>Character stats</title><body><center>");
           htmlContent.append("<br><font color=\"00FF00\">=========>>"+ targetp.getName() +"<<=========</font><br>");
           htmlContent.append("<font color=\"FF0000\">Level:</font> " + targetp.getLevel()+"<br>");
           htmlContent.append("<font color=\"FF0000\">Clan:</font> " + targetp.getClan().getName()+" | ");
           htmlContent.append("<font color=\"FF0000\">Alliance:</font> " + targetp.getClan().getAllyName()+"<br>");
           htmlContent.append("<font color=\"FF0000\">Adena:</font> " + targetp.getAdena()+"<br>");
           htmlContent.append("<font color=\"FF0000\">PvP Kills:</font> " + targetp.getPvpKills()+" | ");
           htmlContent.append("<font color=\"FF0000\">Number of Deaths:</font> " + targetp.getPkKills()+"<br>");
           		
           htmlContent.append("<font color=\"00FF00\">=========>> Faction related <<========="+"</font><br>");
           htmlContent.append("<font color=\"FF0000\">Faction points:</font> " + targetp.getFactionPoints()+"<br>");
           htmlContent.append("</center></body></html>");
           
           NpcHtmlMessage faction = new NpcHtmlMessage(0);
           faction.setHtml(htmlContent.toString());
           activeChar.sendPacket(faction);
           }
           else
                activeChar.sendMessage("No target.");
       }
      return true;
   }
   public String[] getVoicedCommandList()
   {
       return VOICED_COMMANDS;
   }

}

 

First of all try this form.. and dunno how ur faction engine works but maybe u got problems there too.

Second of all You talk to much...

And opcode means the identifyer code id :P of a packet

 

PS: Dude if u could post here an console error.. that would be very helpful :P

And your forum acc is fixed... check ur mxc imbox for the new user and pass

Link to comment
Share on other sites

  • 0

Exactly the same problem :P. So, even if my checks aren't rly optimised (say that to l2j :P I see from their code), it's not the voicedcommandhandler which is bad.

 

Btw, I quote the image, seems you didn't see it. It does the exact same error than doors check, it's that which is strange... Btw, all the rest of faction core is perfectly running (from pvp reward to capture crystals and port to it), so why a commandhandler, which even don't use factionId, bug :/. I don't understand.

 

 

About faction itself, I got a table for faction members, so I didn't even add a column in the "characters" table... And didn't made big customs in L2PcInstance, mainly to put reward for pvp, and clean all karma/pk stuff/flag.

 

Np, if you don't find, I will wait your new archid distrib to see if I can migrate :P. Have you resolved /unstuck and /trade too ?

Link to comment
Share on other sites

  • 0

the npe occurs in the NpcHtmlMessage i saw that many times in interlude use proper code syntax

 

public class stats implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS = { "stats" };

@SuppressWarnings("unchecked")
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	if (command.equalsIgnoreCase("stats"))
	{
		L2PcInstance pc = L2World.getInstance().getPlayer(target);
		if (pc != null)
		{
			NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
			TextBuilder replyMSG = new TextBuilder("<html><body>");
			replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
			replyMSG.append("<br>Statistics for player <font color=\"LEVEL\">" + pc.getName() + "</font><br>");
			replyMSG.append("Total kills <font color=\"FF0000\">" + pc.kills.size() + "</font><br>");
			replyMSG.append("<br>Detailed list: <br>");
			Iterator it = pc.kills.iterator();
			while (it.hasNext())
			{
				replyMSG.append("<font color=\"FF0000\">" + it.next() + "</font><br>");
			}
			replyMSG.append("</body></html>");
			adminReply.setHtml(replyMSG.toString());
			activeChar.sendPacket(adminReply);
		}
	}
	return true;
}

public String[] getVoicedCommandList()
{
	return VOICED_COMMANDS;
}
}

 

heres an example from clean interlude core check the difference its easy to find :)

Link to comment
Share on other sites

  • 0

Ty to help, but if you read what posted Sethek, it's around your code, except the "else incorrect target" and the "NpcHtmlMessage adminReply = new NpcHtmlMessage(5);", which goes from bottom to top, with (5) instead of (0).

 

I think even my method would work, as the null exception is normally checked with targetp != null.

 

That just doesn't want to work :/. Same error, same lines. I suppose it's inherent to voicecommand on l2j archid... Or perhaps I deleted somethig I shouldn't... But why all others targets types tests work...

 

Where in L2PcInstance there will be such a thing ? I haven't anymore the clean last revision of archid to test if it's my error or if archid is like that...

 

I suppose I have to drop it time Archid becomes release, and patch to this new clean system :/.

 

If you haven't others ideas, don't worry too much :/.

 

Here my final .java. For test, I take any char (not GM) I target me and type .faction (don't work both on self and others). The worst is with GM, the selftarget thing works (infinite, until the time you try on others), but not on others... I don't understand. I will try to search in L2PcInstance, around my faction stuff... About the code itself... I don't think I forget anything.

 

package com.l2jarchid.gameserver.handler.voicedcommandhandlers;

import javolution.text.TextBuilder;

import com.l2jarchid.gameserver.handler.IVoicedCommandHandler;
import com.l2jarchid.gameserver.model.actor.instance.L2PcInstance;
import com.l2jarchid.gameserver.network.serverpackets.NpcHtmlMessage;

public class faction implements IVoicedCommandHandler
{
   private static final String[] VOICED_COMMANDS = { "faction" };

   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
   {   
   	if (command.equalsIgnoreCase("faction"))
       {          
           L2PcInstance targetp = (L2PcInstance)activeChar.getTarget();

           if(targetp != null)
           {
           	NpcHtmlMessage faction = new NpcHtmlMessage(5);
           	TextBuilder htmlContent = new TextBuilder("<html><title>Character stats</title><body><center>");
           	htmlContent.append("<br><font color=\"00FF00\">=========>>"+ targetp.getName() +"<<=========</font><br>");
           	htmlContent.append("<font color=\"FF0000\">Level:</font> " + targetp.getLevel()+"<br>");
           	htmlContent.append("<font color=\"FF0000\">Clan:</font> " + targetp.getClan().getName()+" | ");
           	htmlContent.append("<font color=\"FF0000\">Alliance:</font> " + targetp.getClan().getAllyName()+"<br>");
           	htmlContent.append("<font color=\"FF0000\">Adena:</font> " + targetp.getAdena()+"<br>");
           	htmlContent.append("<font color=\"FF0000\">PvP Kills:</font> " + targetp.getPvpKills()+" | ");
           	htmlContent.append("<font color=\"FF0000\">Number of Deaths:</font> " + targetp.getPkKills()+"<br>");     		
           	htmlContent.append("<font color=\"00FF00\">=========>> Faction related <<========="+"</font><br>");
           	htmlContent.append("<font color=\"FF0000\">Faction points:</font> " + targetp.getFactionPoints()+"<br>");
           	htmlContent.append("</center></body></html>");
           	faction.setHtml(htmlContent.toString());
           	activeChar.sendPacket(faction);
           }
       }
      return true;
   }
   public String[] getVoicedCommandList()
   {
       return VOICED_COMMANDS;
   }

}

 

Anyway, ty for your help, I appreciate it.

 

Tryskell.

Link to comment
Share on other sites

  • 0

Believe me or not, but it's the pack which make bug (last revision of Archid, 1292M).

 

From my current project, I have duplicate and "replace with base revision" (it's when you see this feature than you think SVN is really awesome :D), which made me a clean project. I just c/p my handler (the last one i shared, and removed the line concerning faction), put the 2 things in the voicecommandhandler to accept the command ingame and... I still got a NPE ! Buhaha.

 

So it's seems it's the project which is buggy (in the same way, /unstuck and /invite don't work - i thought I made some prog mistakes, but no).

 

Sethek, your actual project is less buggy I hope, else I have to migrate to gracia and it's make me already cry :P

 

About NPE mistakes, it seems I can drop it, I got answer : wait some weeks for new archid release.

Link to comment
Share on other sites

  • 0

the npe occurs in the NpcHtmlMessage i saw that many times in interlude use proper code syntax

 

public class stats implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS = { "stats" };

@SuppressWarnings("unchecked")
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	if (command.equalsIgnoreCase("stats"))
	{
		L2PcInstance pc = L2World.getInstance().getPlayer(target);
		if (pc != null)
		{
			NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
			TextBuilder replyMSG = new TextBuilder("<html><body>");
			replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
			replyMSG.append("<br>Statistics for player <font color=\"LEVEL\">" + pc.getName() + "</font><br>");
			replyMSG.append("Total kills <font color=\"FF0000\">" + pc.kills.size() + "</font><br>");
			replyMSG.append("<br>Detailed list: <br>");
			Iterator it = pc.kills.iterator();
			while (it.hasNext())
			{
				replyMSG.append("<font color=\"FF0000\">" + it.next() + "</font><br>");
			}
			replyMSG.append("</body></html>");
			adminReply.setHtml(replyMSG.toString());
			activeChar.sendPacket(adminReply);
		}
	}
	return true;
}

public String[] getVoicedCommandList()
{
	return VOICED_COMMANDS;
}
}

 

heres an example from clean interlude core check the difference its easy to find :)

 

L2PcInstance pc = L2World.getInstance().getPlayer(target);

 

Thats a null pointer... why? to get a player from l2world you got to use his name you added l2object ans the key object O.o

SO what class contains the name? L2Character (you had to convert it).. my code is simple and works..

 

Tryskell your poroblem si from mmocore you probably use an unstable version of archid... case close... cus you got Thread Npes..

In this case the problem must be smth from your java env or the pack being fucked up xD

Link to comment
Share on other sites

  • 0

Tryskell your poroblem si from mmocore you probably use an unstable version of archid... case close... cus you got Thread Npes..

In this case the problem must be smth from your java env or the pack being -beep-ed up xD

 

It's what I conclued too :P. Whatever I do, it fails. Java env is fine, as the problem is really located to that. Btw, it's the last revision (1292M). I added you to MSN, so we can talk a lil longer :P.

 

My case is closed, let's see if archid "new generation" offers less instability :P.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...