ldonahue

init() method of a Tool add-in executes more than once

Discussion created by ldonahue on Jan 11, 2012
I've been working on a Java Tool add-in and I noticed that the init(IApplication) method of a Tool executes the contents of that method more than once.  Why is that?

http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/0001/00010000041v000000.htm

When working with one of the ArcGIS Desktop applications it is quite possible that you might need to access various items within the applications. For example, in ArcMap you might wish to access the map (that is, data frame) or layers contained within a map. Your Java application cannot just instantiate an instance of the ArcMap application; instead you are passed a reference to an object that will give you the application that the tool is contained within. The init() method serves this purpose as well as defining any logic that is necessary to initialize your tool (for example: instantiate objects that are needed in your mousePressed() method as one example).


I had been placing some code within the init() method to create a view and controller object and noticed that my actionListener for creating a point feature was creating one good point and several null geometry points. Debugging the code showed me that the init() method of a Tool loops through the code several times.

Outcomes