我在调试时遇到错误:
System.NullReferenceException:未将对象引用设置为对象的实例 在COServer_Project.Mobs.SpawnAllMobs()
在C:\ Users \ Donavon Decker \ Desktop \ New folder \ COServerProject \ Entities.cs:第189行
这是代码:
public static void SpawnAllMobs()
{
try
{
int MobsSpawned = 0;
int MobSpawnsToSpawn = DataBase.MobSpawns.Length;
for (int j = 0; j < MobSpawnsToSpawn; j++)
{
uint[] ThisSpawn = DataBase.MobSpawns[j];
string[] ThisMob = null;
foreach (string[] FindId in DataBase.Mobs)
{
if (FindId[0] == Convert.ToString(ThisSpawn[1]))
{
ThisMob = FindId;
}
}
for (int n = 0; n < Convert.ToInt32(ThisSpawn[2]); n++)
{
uint UID = (uint)General.Rand.Next(400000, 500000);
short spawn_x = (short)General.Rand.Next(Convert.ToInt16(ThisSpawn[3]), Convert.ToInt16(ThisSpawn[5]));
short spawn_y = (short)General.Rand.Next(Convert.ToInt16(ThisSpawn[4]), Convert.ToInt16(ThisSpawn[6]));
while (AllMobs.Contains(UID))
{
UID = (uint)General.Rand.Next(400000, 500000);
}
SingleMob Mob = new SingleMob(spawn_x, spawn_y, Convert.ToInt16(ThisSpawn[7]), uint.Parse(ThisMob[3]), uint.Parse(ThisMob[3]), short.Parse(ThisMob[6]), short.Parse(ThisMob[7]), UID, ThisMob[2], int.Parse(ThisMob[1]), short.Parse(ThisMob[4]), (byte)General.Rand.Next(8), byte.Parse(ThisMob[5]));
AllMobs.Add(UID, Mob);
MobsSpawned++; ;
}
}
DataBase.Mobs = null;
DataBase.MobSpawns = null;
General.WriteLine("Spawned " + MobsSpawned + " mobs.");
}
catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); }
}
这是第189行:
int MobSpawnsToSpawn = DataBase.MobSpawns.Length;
我不知道如何解决此问题。如果有人可以提供帮助,那就太棒了。