CampaignService service = new CampaignService();
Campaign[] CampaignList = service.getAllCampaigns(0);
foreach (Campaign c in CampaignList)
{
Keyword[] KeywordList = c.campaignNegativeKeywords;
foreach(Keyword k in KeywordList)----未将对象引用设置到对象的实例,为什么呀?????
{
ListBox1.Items.Add("");
ListBox1.Items.Add(k.id.ToString());
ListBox1.Items.Add(k.text);
}
}

解决方案 »

  1.   

    不知道原因,不过下面这个可能对你有些参考价值:
    类数组在定义并初始化时,并没有实际创建比如有个类叫class1
    class1[] classes=new class1[10];这样其实并未创建10个实例而只是创建了一个够放10个class1的数组空间而已。
      

  2.   

    因为c.campaignNegativeKeywords为NULL,所以出异常
      

  3.   

    加个条件判断一下就可以了:
    if (KeywordList != null) {
    foreach(Keyword k in KeywordList)
    {
    ListBox1.Items.Add("");
    ListBox1.Items.Add(k.id.ToString());
    ListBox1.Items.Add(k.text);
    }
    }
      

  4.   

    加个条件判断一下就可以了:
    if (KeywordList != null) {
    foreach(Keyword k in KeywordList)
    {
    ListBox1.Items.Add("");
    ListBox1.Items.Add(k.id.ToString());
    ListBox1.Items.Add(k.text);
    }
    }