I have searched for the answer and have tried many different solutions but none seem to work!.
Using EveAI http://wiki.eve-id.net/EveAI
System.NullReferenceException: Object reference not set to an instance of an object. Form1.PopulateMarketIDs()
private void PopulateMarketIDs()
{
eapi.EveApi MyApi = new eapi.EveApi();
List<int> MarketIDs = new List<int>();
string SelectedItem;
List<EveAI.Product.ProductType> Products = new List<EveAI.Product.ProductType>();
foreach (string item in kryptonListBox1.Items)
{
SelectedItem = item;
foreach (EveAI.Product.ProductType Prod in MyApi.EveApiCore.ProductTypes)
{
if (Prod.MarketGroup != null)
{
if (Prod.MarketGroup.ParentGroup.Name == SelectedItem)
{
Products.Add(Prod);
}
else
{
if (Prod.MarketGroup.Name == SelectedItem)
{
Products.Add(Prod);
}
}
}
}
}
}
The kryptonListBox1 contains at least one item such as "Mining Drones". It works fine, it lists the products as it should, but when it gets to the last product (displays) and then crashes with the null error.
I am aware that it will not return anything, I have snipped out the output section of it.
i think your trouble is into the
MyApi.EveApiCore.ProductTypes
is this a static resource ?
else you must reference it before use it.
I have changed the code to:
foreach (string item in kryptonListBox1.Items)
{
foreach (EveAI.Product.ProductType Prod in MyApi.EveApiCore.ProductTypes)
{
if (Prod.MarketGroup != null)
{
if (Prod.MarketGroup.Name == item)
{
if (Prod.Name.Contains("Blueprint") == false)
{
kryptonListBox2.Items.Add(Prod.Name);
Products.Add(Prod);
}
}
}
}
}
foreach (EveAI.Product.ProductType T in Products)
{
kryptonListBox3.Items.Add(MyApi.EveApiCore.GetIdForObject(T));
}
And this is working great.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.