[help]bit of help

12/21/2010 06:11 coreymills#1
Error:
Quote:
System.NullReferenceException: Object reference not set to an instance of an object.
at NewestCOServer.PacketHandling.Teleport.Handle(Game Client GC, Byte[] Data) in C:\Users\Corey\Downloads\BetaCo\PacketHandling\Tel eport.cs:line 22
at NewestCOServer.PacketHandler.Handle(GameClient GC, Byte[] PData) in C:\Users\Corey\Downloads\BetaCo\PacketHandler.cs:l ine 758
PacketHandler.cs Line 758:
Code:
PacketHandling.Teleport.Handle(GC, Data);
Teleport.cs Line 22:
Code:
[COLOR="Red"]foreach (Game.Item I in GC.MyChar.Inventory)[/COLOR]//error line
                {
                    if (I != null)
                    {
                        GC.AddSend(Packets.AddItem(I, 0));
                    }
                }
12/21/2010 07:44 InfamousNoone#2
One of the 3 things is null. GC, MyChar or Inventory. If I had to take a guess, I'd say MyChar. Why it's null though, I can't offer and support.
12/21/2010 12:29 _DreadNought_#3
Make sure the character is not null. add the line
Code:
if (GC.MyChar != null)
{
[COLOR="Lime"]//the foreach code.[/COLOR]
}
12/21/2010 15:46 coreymills#4
nope its still giving the same error
12/21/2010 15:57 Korvacs#5
Learn how to debug your code using breakpoints.
12/21/2010 15:58 teroareboss1#6
if(GC.MyChar.Inventory.Count > 0)
{
....
}
12/21/2010 16:52 coreymills#7
Quote:
Originally Posted by Korvacs View Post
Learn how to debug your code using breakpoints.
i recently converted my source to mysql it was the betaco ini source and i'm still learning to code but i was working at that problem for 2 days
12/22/2010 16:48 { Angelius }#8
Go to telport.cs and remove these lines
Quote:
foreach (Game.Item I in GC.MyChar.Inventory)//error line
{
if (I != null)
{
GC.AddSend(Packets.AddItem(I, 0));
}
}
you dont need it any more cus you are not updating/converting you are just copy pasting the load/save/sql commands
but trust me thats not gonna work delete the whole source and start learning/building your own Pserver
Ps.Dont waste your time with those sources and start learning how to do your own shit :xD
12/22/2010 20:00 pro4never#9
As already stated, something is null.

Your character, your inventory or the client itself (which should never happen as it would need to NOT be null for this to trigger).

Place a breakpoint on this line and when it hits it you will be able to see what the value/structure for all these things are. Find the one that is null and there's your problem. Then backtrack it to ensure this doesn't happen again.