[HELP] Please help me understand this error

09/03/2008 20:50 taguro#1
Code:
[COLOR=#000000]System.NullReferenceExeption: Object reference no set to an instance of an object. at COServerProject.Client.GetPacket(Byte[] data) in c:\xxx\client.cs:line 7785[/COLOR]
I need specifics. All my reading has told me is that this error occurs when a string is not null. Knowing the quick fix would be nice, but understanding the error would pwn.

Thanks in advance for your helpful replies.
09/03/2008 21:23 InfamousNoone#2
Paste the getpacket function too, lol.
09/03/2008 22:37 taguro#3
Quote:
Originally Posted by InfamousNoone View Post
Paste the getpacket function too, lol.
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.Client.GetPacket(Byte[] data) in C:xxxClient.cs:line 7785
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
I'm not sure if this is what your looking for, but this is the whole error report from my serverlog. If you need more info, add me on msn: [Only registered and activated users can see links. Click Here To Register...]

and thanks for the quick response.
09/03/2008 22:41 MushyPeas#4
Quote:
Originally Posted by taguro View Post
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.Client.GetPacket(Byte[] data) in C:xxxClient.cs:line 7785
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
I'm not sure if this is what your looking for, but this is the whole error report from my serverlog. If you need more info, add me on msn: [Only registered and activated users can see links. Click Here To Register...]

and thanks for the quick response.
He means he has to see the code (the function) that is causing the errors, otherwise he can't possibly guess what needs to be fixed.
09/03/2008 22:45 alexbigfoot#5
Quote:
Originally Posted by taguro View Post
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.Client.GetPacket(Byte[] data) in C:xxxClient.cs:line 7785
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
System.NullReferenceException: Object reference not set to an instance of an object.
   at COServer_Project.DataBase.Authenticate(String UserName, String Password) in C:xxxDataBase.cs:line 1709
I'm not sure if this is what your looking for, but this is the whole error report from my serverlog. If you need more info, add me on msn: [Only registered and activated users can see links. Click Here To Register...]

and thanks for the quick response.
lol?Hybrid was saying something like:
go to line 7785 from client.cs and post here the line....
09/03/2008 23:13 taguro#6
Quote:
Originally Posted by alexbigfoot View Post
lol?Hybrid was saying something like:
go to line 7785 from client.cs and post here the line....
Crap, sorry dumb moment. Here you are: (Client.cs statement)

Code:
  if (Control <= 16 && Control >= 10)
                                {
                                    string TheEquip = "";

                                    if (Control == 10)
                                        TheEquip = MyChar.Equips[1];
                                    if (Control == 11)
                                        TheEquip = MyChar.Equips[2];
                                    if (Control == 12)
                                        TheEquip = MyChar.Equips[3];
                                    if (Control == 13)
                                        TheEquip = MyChar.Equips[4];
                                    if (Control == 14)
                                        TheEquip = MyChar.Equips[6];
                                    if (Control == 15)
                                        TheEquip = MyChar.Equips[8];
                                    if (Control == 16)
                                        TheEquip = MyChar.Equips[5];

                                    byte Pos = 0;

                                    if (Control == 10)
                                        Pos = 1;
                                    if (Control == 11)
                                        Pos = 2;
                                    if (Control == 12)
                                        Pos = 3;
                                    if (Control == 13)
                                        Pos = 4;
                                    if (Control == 14)
                                        Pos = 6;
                                    if (Control == 15)
                                        Pos = 8;
                                    if (Control == 16)
                                        Pos = 5;

                                    string[] Splitter = TheEquip.Split('-');
                                    uint ItemId = uint.Parse(Splitter[0]);

                                    if (!Other.Upgradable(ItemId))
                                        return;

                                    byte RequiredMets = 0;
                                    if (Other.ItemInfo(ItemId)[3] < 120)
                                    {
                                        RequiredMets = (byte)(Other.ItemInfo(ItemId)[3] / 10);
                                        if (RequiredMets == 0)
                                            RequiredMets = 1;
                                    }
                                    if (RequiredMets != 0)
                                    {
                                        if (Other.ItemQuality(ItemId) < 7)
                                            RequiredMets = 2;
                                        if (Other.ItemQuality(ItemId) == 7)
                                            RequiredMets = (byte)(2 + RequiredMets / 5);
                                        if (Other.ItemQuality(ItemId) == 8)
                                            RequiredMets = (byte)(RequiredMets * 2.6);
                                        if (Other.ItemQuality(ItemId) == 9)
                                            RequiredMets = (byte)(RequiredMets * 3.1);
                                    }
Here is the specific line(7785):
Code:
                                    string[] Splitter = TheEquip.Split('-');
And here is the Database.cs statement:
Code:
  public static byte Authenticate(string UserName, string Password)
        {
            try
            {
                MySqlDataAdapter DataAdapter = new MySqlDataAdapter("SELECT * FROM `Accounts` WHERE `AccountID` = '" + UserName + "'", Connection);
                DataSet DSet = new DataSet();

                DataAdapter.Fill(DSet, "Account");

                if (DSet != null && DSet.Tables["Account"].Rows.Count > 0)
                //if (DSet.Tables["Account"].Rows.Count > 0)
                {
                    DataRow DR = DSet.Tables["Account"].Rows[0];

                    string Pass = (string)DR["Password"];
                    if (Pass == Password || Pass == "")
                    {
                        if (Pass == "")
                        {
                            MySqlCommand Command = new MySqlCommand("UPDATE `Accounts` SET `Password` = '" + Password + "' WHERE `AccountID` = '" + UserName + "'", Connection);
                            Command.ExecuteNonQuery();
                        }

                        uint LogonCount = (uint)DR["LogonCount"];
                        LogonCount++;

                        MySqlCommand Comm = new MySqlCommand("UPDATE `Accounts` SET `LogonCount` = " + LogonCount + " WHERE `AccountID` = '" + UserName + "'", Connection);
                        Comm.ExecuteNonQuery();

                        return Convert.ToByte((uint)DR["LogonType"]);
                    }
                    else
                        return 0;
                }
                else
                    return 0;
            }
            catch (Exception Exc) { General.WriteLine(Exc.ToString()); return 0; }
        }
and line 1709:
Code:
                DataSet DSet = new DataSet();
09/03/2008 23:39 InfamousNoone#7
Quote:
Originally Posted by taguro View Post
Crap, sorry dumb moment. Here you are: (Client.cs statement)

Code:
  if (Control <= 16 && Control >= 10)
                                {
                                    string TheEquip = "";

                                    if (Control == 10)
                                        TheEquip = MyChar.Equips[1];
                                    if (Control == 11)
                                        TheEquip = MyChar.Equips[2];
                                    if (Control == 12)
                                        TheEquip = MyChar.Equips[3];
                                    if (Control == 13)
                                        TheEquip = MyChar.Equips[4];
                                    if (Control == 14)
                                        TheEquip = MyChar.Equips[6];
                                    if (Control == 15)
                                        TheEquip = MyChar.Equips[8];
                                    if (Control == 16)
                                        TheEquip = MyChar.Equips[5];

                                    byte Pos = 0;

                                    if (Control == 10)
                                        Pos = 1;
                                    if (Control == 11)
                                        Pos = 2;
                                    if (Control == 12)
                                        Pos = 3;
                                    if (Control == 13)
                                        Pos = 4;
                                    if (Control == 14)
                                        Pos = 6;
                                    if (Control == 15)
                                        Pos = 8;
                                    if (Control == 16)
                                        Pos = 5;

                                    if (TheEquip != null) // ADD THIS
                                    { // ADD THIS
                                    string[] Splitter = TheEquip.Split('-');
                                    uint ItemId = uint.Parse(Splitter[0]);

                                    if (!Other.Upgradable(ItemId))
                                        return;

                                    byte RequiredMets = 0;
                                    if (Other.ItemInfo(ItemId)[3] < 120)
                                    {
                                        RequiredMets = (byte)(Other.ItemInfo(ItemId)[3] / 10);
                                        if (RequiredMets == 0)
                                            RequiredMets = 1;
                                    }
                                    if (RequiredMets != 0)
                                    {
                                        if (Other.ItemQuality(ItemId) < 7)
                                            RequiredMets = 2;
                                        if (Other.ItemQuality(ItemId) == 7)
                                            RequiredMets = (byte)(2 + RequiredMets / 5);
                                        if (Other.ItemQuality(ItemId) == 8)
                                            RequiredMets = (byte)(RequiredMets * 2.6);
                                        if (Other.ItemQuality(ItemId) == 9)
                                            RequiredMets = (byte)(RequiredMets * 3.1);
                                    }
                                    } // ADD THIS
Here is the specific line(7785):
Code:
                                    string[] Splitter = TheEquip.Split('-');
And here is the Database.cs statement:
Code:
  public static byte Authenticate(string UserName, string Password)
        {
            try
            {
                MySqlDataAdapter DataAdapter = new MySqlDataAdapter("SELECT * FROM `Accounts` WHERE `AccountID` = '" + UserName + "'", Connection);
                DataSet DSet = new DataSet();

                DataAdapter.Fill(DSet, "Account");

                if (DSet != null && DSet.Tables["Account"].Rows.Count > 0)
                //if (DSet.Tables["Account"].Rows.Count > 0)
                {
                    DataRow DR = DSet.Tables["Account"].Rows[0];

                    string Pass = (string)DR["Password"];
                    if (Pass == Password || Pass == "")
                    {
                        if (Pass == "")
                        {
                            MySqlCommand Command = new MySqlCommand("UPDATE `Accounts` SET `Password` = '" + Password + "' WHERE `AccountID` = '" + UserName + "'", Connection);
                            Command.ExecuteNonQuery();
                        }

                        uint LogonCount = (uint)DR["LogonCount"];
                        LogonCount++;

                        MySqlCommand Comm = new MySqlCommand("UPDATE `Accounts` SET `LogonCount` = " + LogonCount + " WHERE `AccountID` = '" + UserName + "'", Connection);
                        Comm.ExecuteNonQuery();

                        return Convert.ToByte((uint)DR["LogonType"]);
                    }
                    else
                        return 0;
                }
                else
                    return 0;
            }
            catch (Exception Exc) { General.WriteLine(Exc.ToString()); return 0; }
        }
and line 1709:
Code:
                DataSet DSet = new DataSet();
You can fix the indent, or the compiler will lol; tanel did such a shit job on lotf I'm not bothering to optimize the code.
09/03/2008 23:54 taguro#8
Quote:
Originally Posted by InfamousNoone View Post
You can fix the indent, or the compiler will lol; tanel did such a shit job on lotf I'm not bothering to optimize the code.
I appreciate you taking the time to look this over, but what does the indent have to do with the error I'm receiving.
09/04/2008 00:27 InfamousNoone#9
The string "TheEquip" is null, and it's trying to split it.