0

i get this error when i try to compile my program using Visual Studio and Enterprise Architect.

I'm writing a tool for Enterprise Architect, and i have to make a graph, and i continue to get this error, i don't know what to do.

The code that i have problem with is:

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

Please help if you know how.

Thank you a lot!

Tigran
  • 61,654
  • 8
  • 86
  • 123
Defi
  • 91
  • 1
  • 2
  • 12
  • Which line the error appears on? – Péter Török Apr 16 '12 at 11:53
  • the problem is in the assignement of maindiagram and says that it result null. And i don't get it how it can be null. And the other is in the first foreach with the maindiagram i assume for the same reason. I have to resolve the maindiagram problem, but i don't know how, i tought that GetCurrentDiagram() get you the diagram that you have open in enterprise architect. – Defi Apr 16 '12 at 18:26

2 Answers2

0

It's impossible to understand what is going on in this code, just by message provided.

Tigran
  • 61,654
  • 8
  • 86
  • 123
0

repository could be null - you should be doing null checks on parameter arguments to determine whether you can proceed or not; also maindiagram could be null (for all we know, if repository is something, then GetCurrentDiagram might return null.

Both of these things are accessed in a way that could cause your problem.

diagramList isn't present in the scope of the method so assuming it has a more liberal scope: this could also be nothing, yet you call Add on it. You also iterate through this as if it is something, and without checking that an element is null or not, try to access its properties.

In short, there are numerous places where this might occur in the code you posted. You should be more specific about where the error is actually occurring, however, the answer will be the same: something is nothing.

Community
  • 1
  • 1
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • I know that something is null, and how i resolve one, i get other errors, always the same. I get the errors about the "maindiagram" it seams null but i don't get it why, and the "foreach in maindiagram.DiagramObject". Do you know why my currentdiagram() doesn't work and don't give the value to the maindiagram? – Defi Apr 16 '12 at 12:46