簡體   English   中英

System.NullReferenceException:EveAI

[英]System.NullReferenceException: EveAI

我已經搜索了答案,並嘗試了許多不同的解決方案,但是似乎都沒有用!

使用EveAI http://wiki.eve-id.net/EveAI

System.NullReferenceException:對象引用未設置為對象的實例。 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);
                    }
                }
            }
        }
    }
}

kryptonListBox1包含至少一項,例如“ Mining Drones”。 它工作正常,它按應有的方式列出了產品,但是當它到達最后一個產品(顯示)時發生崩潰,並出現空錯誤。

我知道它不會返回任何內容,我已經摘錄了它的輸出部分。

我認為你的麻煩是

MyApi.EveApiCore.ProductTypes

這是靜態資源嗎?

否則在使用前必須先引用它。

我已將代碼更改為:

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));
}

這很好用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM