當我嘗試使用Visual Studio和Enterprise Architect編譯我的程序時出現此錯誤。錯誤:未將對象引用設置爲對象的實例企業架構師和視覺工作室
我正在爲Enterprise Architect編寫一個工具,而且我必須製作一個圖表,並且我仍然會出現此錯誤,我不知道該怎麼辦。
,我有問題的代碼是:
public Graph(EA.Repository repository)
{
EA.Diagram maindiagram;
this.modelRepository = repository;
maindiagram = repository.GetCurrentDiagram(); //recupero del diagramma
this.diagramId = maindiagram.DiagramID; //identificativo del diagramma
//inizializzazione nodi
Collection nodeCollection = maindiagram.DiagramObjects;
nodeList = new ArrayList();
foreach (DiagramObject diagram in maindiagram.DiagramObjects)
{
diagramList.Add(diagram);
foreach (Element element in diagramList)
{
if (element.Type == "Class"|| element.Type == "Component"||element.Type == "Package")
{ nodeList.Add(new Node(diagram, ref repository)); }
}
}
//inizializzazione archi
Collection linkCollection = maindiagram.DiagramLinks;
linkList = new ArrayList();
foreach (DiagramLink edge in maindiagram.DiagramLinks)
{
edgeList.Add(edge);
foreach(Connector connector in edgeList)
if (connector.Type == "Association" || connector.Type == "Aggregation" || connector.Type == "Compose" || connector.Type == "Dependency"
|| connector.Type == "Generalization" || connector.Type == "Realization")
{ linkList.Add(new Link (edge, ref repository));}
}
請幫助,如果你知道怎麼辦。
非常感謝!
哪條線出現錯誤? – 2012-04-16 11:53:17
問題在於maindiagram的分配,並說它導致null。我不明白它如何可以爲空。另一個是我爲同樣原因假設的第一個foreach。我必須解決maindiagram問題,但我不知道如何,我想GetCurrentDiagram()可以幫助您獲得您在企業架構師中開放的關係圖。 – Defi 2012-04-16 18:26:44