Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 07:24

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



NulllReferenceException (Loading NPC)

Discussion on NulllReferenceException (Loading NPC) within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
NulllReferenceException (Loading NPC)

I was trying to load an NPC from a MySQL database, but I get NullReference in this code:

PHP Code:
private void LoadNpcs()
        {
            
Database.MySqlCommand command = new Conquer_Online_Server.Database.MySqlCommand(Conquer_Online_Server.Database.MySqlCommandType.SELECT);
            
command.Select("npcs").Where("mapid"ID);
            
Database.MySqlReader reader = new Conquer_Online_Server.Database.MySqlReader(command);
                while (
reader.Read())
                {
                    
INpc npc = new Network.GamePackets.NpcSpawn();
                    
npc.UID reader.ReadUInt32("id");
                    
npc.Type reader.ReadUInt16("lookface");
                    
npc.Kind = (Enums.NpcKind)reader.ReadByte("type");
                    
npc.reader.ReadUInt16("cellx"); ;
                    
npc.reader.ReadUInt16("celly");
                    
npc.MapID ID;
                    
AddNpc(npc);
                }
            
reader.Close();
        } 
Any idea why is it Null? Impulse 5165.
~Crystaline is offline  
Old 10/09/2013, 19:22   #2
 
elite*gold: 0
Join Date: Feb 2006
Posts: 726
Received Thanks: 271
Could be the ID variable you are using as a parameter to search for.

Or one of the fields in the table is null that you are trying to read and assign to npc
Aceking is offline  
Old 10/09/2013, 21:13   #3
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
There is about 20 reasons for that to be caused, more info?
_DreadNought_ is offline  
Old 10/09/2013, 21:18   #4
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,205
Received Thanks: 4,107
Put a breakpoint at the top of that method, then follow it down and step into the MySql wrapper. See where the program crashes (it should tell you as you step over the null reference). It probably helps to know what a null reference is.
Quote:
The null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables. NullReferenceException is common. It indicates that you are trying to access member fields, or function types, on an object reference that points to null.
For info on how to debug your server, use my tutorial (below).
Spirited is offline  
Old 10/10/2013, 02:20   #5
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
After breakpointing, it says that "command" and "reader" are Null. I have no idea why is it null. I haven't experience this before, when I added loading the NPC through MySQL.
~Crystaline is offline  
Old 10/10/2013, 07:15   #6
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,205
Received Thanks: 4,107
Quote:
Originally Posted by ~Crystaline View Post
After breakpointing, it says that "command" and "reader" are Null. I have no idea why is it null. I haven't experience this before, when I added loading the NPC through MySQL.
See if the constructor runs into any problems. It might be that it can't find the table, and thus something isn't being initialized in the constructor. Are you positive that the server is set up correctly? If you are, see what happens in the constructor. Step through it.
Spirited is offline  
Old 10/10/2013, 15:04   #7
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
Is the variable "ID" static or a local variable? Not sure where that value is being defined.

#edit Nvm, I now see that the AddNPC is being called locally. Assume this is being called from an instance of a map class. Derp
12k is offline  
Old 10/10/2013, 16:34   #8
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
I don't know what to call this one, but anyway I name it as "caller" Okay, I tried breakpointing the "caller" which is "LoadNpcs();" and this one thing here appeared.



And I think this is causing the problem.

Edit:

-LoadNPC is a method, which is not valid in the given context.
~Crystaline is offline  
Old 10/10/2013, 17:40   #9
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,205
Received Thanks: 4,107
Quote:
Originally Posted by ~Crystaline View Post
I don't know what to call this one, but anyway I name it as "caller" Okay, I tried breakpointing the "caller" which is "LoadNpcs();" and this one thing here appeared.



And I think this is causing the problem.

Edit:

-LoadNPC is a method, which is not valid in the given context.
I don't think that would be the problem. It wouldn't compile if there was a missing reference to a method. Try stepping into it using the tutorial I created. Step through each line and see exactly what isn't being initialized. You can mouse over the variables as I've mentioned in the tutorial.
Spirited is offline  
Old 10/15/2013, 15:34   #10
 
shadowman123's Avatar
 
elite*gold: 0
Join Date: Aug 2007
Posts: 1,525
Received Thanks: 230
Which line is the Error Located in ?
shadowman123 is offline  
Old 10/17/2013, 09:44   #11
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
Quote:
Originally Posted by shadowman123 View Post
Which line is the Error Located in ?
PHP Code:
while (reader.Read())
            {
                
INpc npcs = new Network.GamePackets.NpcSpawn();
                
npcs.UID reader.ReadUInt32("id");
                
npcs.Type reader.ReadUInt16("lookface");
                
npcs.Kind = (Enums.NpcKind)reader.ReadByte("type");
                
npcs.reader.ReadUInt16("cellx");
                
npcs.reader.ReadUInt16("celly");
                
npcs.MapID ID;
                
AddNpc(npcs);
            } 
Line 351 which is while (reader.Read())
~Crystaline is offline  
Old 10/17/2013, 14:36   #12
 
.Beatz's Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 1,190
Received Thanks: 516
Quote:
Originally Posted by ~Crystaline View Post
PHP Code:
while (reader.Read())
            {
                
INpc npcs = new Network.GamePackets.NpcSpawn();
                
npcs.UID reader.ReadUInt32("id");
                
npcs.Type reader.ReadUInt16("lookface");
                
npcs.Kind = (Enums.NpcKind)reader.ReadByte("type");
                
npcs.reader.ReadUInt16("cellx");
                
npcs.reader.ReadUInt16("celly");
                
npcs.MapID ID;
                
AddNpc(npcs);
            } 
Line 351 which is while (reader.Read())
Can you please screenshot the nullreference and post it here
.Beatz is offline  
Old 10/17/2013, 16:46   #13
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
Quote:
Originally Posted by .Beatz View Post
Can you please screenshot the nullreference and post it here
~Crystaline is offline  
Old 10/17/2013, 17:21   #14
 
.Beatz's Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 1,190
Received Thanks: 516
Please link me to the source you are using, I will have a look through it and find out what's going wrong... Will be much easier this way
.Beatz is offline  
Old 10/17/2013, 18:32   #15
 
~Crystaline's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 179
Received Thanks: 55
<-- There.
~Crystaline is offline  
Reply


Similar Threads Similar Threads
SF MOD - FHM LOADING MAP
09/22/2013 - Soldier Front Hacks, Bots, Cheats & Exploits - 5 Replies
FHM LOADING MAP https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak -ash3/1237775_245094872306482_161287111_n.jpg Download link: CLICK ME Instructions: 1. Extract the file (pass: kurimaw) 2. Copy and Paste the files.. menu_52(FHM loading map) and menu_65 (chix ads wall) to SF FOLDER/DATA/MENU 3. Don't forget to back up the original file
D.O Not Loading
06/16/2013 - DarkOrbit - 9 Replies
Heys guys my darkorbit is not loading up it gets full way on the loading bar and just stops
KGC Loading FIX
09/15/2012 - Grand Chase - 2 Replies
this is a fix to the kgc loading problem (when you select a server it shuts off) please try if it will work for you too basically you just turn of aero, the glass like interface, if you're using windows vista, 7 or 8 switch to windows 7 basic theme if it fails then you need to upgrade your graphics card* that's about it tried it and worked for me and i don't even have an integrated graphics xD and if this happens in PH (rebirth) this could help o_o
D/C when loading into a map.
07/23/2010 - Dekaron Private Server - 2 Replies
After I change my character into GM and add all the exp and money, I get on my client and login. Then it loads for loa map and at the end of the loading ... it pauses for couple seconds .. Then the Loa Map screen comes up and out of no where the client d/c. How do I come around in fixing this? :confused:
now loading
06/27/2009 - Grand Chase Philippines - 1 Replies
why is that my gc... when i start the game in dungoen... it is always in NOW LOADING///.......



All times are GMT +1. The time now is 07:24.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.