Getting the application reference for an addin

Discussion created by DominikW on May 19, 2011
Hi there,

Currently I'm facing the following problem:

Within my addin there are two Classes: "ImportGPX" (which contains the main business logic) and "Helper" (which contains helping functions like getting the spatial reference, etc.). Within the "Helper"-Class resides the following function

public static IMap GetMap() throws AutomationException, IOException
  IDocument document = null;
  IMxDocument mxDocument = (IMxDocument) document;
  return mxDocument.getFocusMap();

Obviously the code above results in an NullPointerException.

Since I initialize the addin within the "ImportGPX"-class, I want to know how to get an application reference into the code mentioned above.

My first guess was to copy the IApplication object by declaring a similar object within "Helper" and passing the data to this object when the function

public void init(IApplication app)
  { = app;

is being called. But this results in a crash of ArcMap.