Problems with java add-ins

4526
17
05-23-2012 05:10 AM
AlbertoDe_Luca
New Contributor
Hello everyone.

Since ArcGIS 10 supports java for desktop development too, I tried to set up a java add-in for ArcMap. Before writing my own add-in I had a go with one of the samples provided by the Java SDK, called "simpleaddin".

I can add the add-in to ArcMap without problems, and I can see it listed in the Add-In Manager.

Unfortunately, when I bring up the add-in toolbar (SampleJava Toolbar) in ArcMap, no custom commands are shown, just a bunch of labels saying "missing". Native ArcMap commands (like Fixed Zoom Out) are visible on the toolbar though (see attached image).

I also tried to create my own add-in, following the instructions given in this video:

http://resources.arcgis.com/gallery/video/java/details?entryID=F8A0A38E-1422-2418-7FA3-CC2C83ED9674

but in this case I couldn't even find my custom command in the commands list under "Customize".

I tried on two boxes, both running win7/64 and ArcMap w/ the most recent SP available installed.

Any clues?

Thanks a bunch
Alberto
0 Kudos
17 Replies
AlbertoDe_Luca
New Contributor
Thank you guys for your patience.

I attached to this message the screen cap from Eclipse and the content of the xml file itself.

Alberto

<?xml version="1.0" encoding="UTF-8"?>
<ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Name>TestAddIn3</Name>
  <AddInID>92421ca6-0137-1000-5000-93a2889e0000</AddInID>
  <Description></Description>
  <Version>1.0</Version>
  <Image></Image>
  <Author></Author>
  <Company></Company>
  <Date>Mon May 28 09:03:55 CEST 2012</Date>
  <Targets>
    <Target name="Desktop" version="10.0"/>
  </Targets>
  <AddIn language="JAVA" library="TestAddIn3.jar">
    <ArcMap>
      <Commands>
        <Button caption="NewButton1" category="JavaCommands" class="Button1" id="button1"/>
      </Commands>
    </ArcMap>
  </AddIn>
</ESRI.Configuration>
0 Kudos
LeoDonahue
Occasional Contributor III
Excellent.

Now, I notice that the name of your "class" is named "Button1".  Did you create that class by clicking on the "class" hyperlink, or did you browse to the class named "Button1"?
0 Kudos
AlbertoDe_Luca
New Contributor
After creating the add-in, I just pushed the "Add..." button to created a Button, and the class was already named Button1. Then, I clicked the "class" hyperlink, and accepted all the default values (just clicked "Finish").

Alberto
0 Kudos
LeoDonahue
Occasional Contributor III
Ok.  last thing I can suggest then is to delete your Add-in cache.

It will be located here:  C:\Users\Alberto?\AppData\Local\ESRI\Desktop10.0\AssemblyCache

Find the directory that has your add-in and delete the directory.  Then re-export the add-in and try again.
0 Kudos
AlbertoDe_Luca
New Contributor
I deleted the add-in cache, but that didn't change things either.

Do you know if there is any log file I could check? I enabled the "Create console..." option from the ArcGIS Java Configuration Tool, but no error messages are shown...

Alberto
0 Kudos
LeoDonahue
Occasional Contributor III
C:\Users\Alberto?\AppData\Local\ESRI\Desktop10.0\Java\Log

I don't think you'll see anything in the logs if your class is not loading.

This is the contents of my most recent log file:

INFO::Using the following arguments to create the JVM
-Djava.class.path=C:\Program Files (x86)\ArcGIS\Desktop10.0\\java\lib\arcobjects.jar
-Xms64m
-Xmx128m
-Xss512k
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8013
INFO::Successfully created an instance of : com/esri/arcgis/addinframework/AddInFactory
0 Kudos
LeoDonahue
Occasional Contributor III
Alberto,

When you clicked the "class" hyperlink to create your Button 1 class, was it created in the right project?  Just checking.  I suspect that something is wrong with the way the Button 1 class was created.

This should be what a generic Button Class looks like, if you override/implement the init() method.

import java.io.IOException;

import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.interop.AutomationException;


public class Button1 extends Button {

    /**
     * Called when the button is clicked.
     * 
     * @exception java.io.IOException if there are interop problems.
     * @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
     */
    @Override
    public void onClick() throws IOException, AutomationException {
        // TODO Auto-generated method stub

    }

    @Override
    public void init(IApplication app) throws IOException, AutomationException {
        // TODO Auto-generated method stub
        super.init(app);
    }

}
0 Kudos
AlbertoDe_Luca
New Contributor
ldonahue,

when I clicked the "class" hyperlink to create my "Button 1" class, the options on the dialog were the same as yours, and the class was created in the right project. But looking at your class code I noticed that my class was missing the init method (I should have checked that in the first place, my bad)!!!

Nevertheless, after adding the missing method, I still couldn't see my button in the Customize dialog. I checked the log files, and realized that I had set the wrong JDK version (1.7) in Eclipse when I created the add-in:

INFO::Successfully created an instance of : com/esri/arcgis/addinframework/AddInFactory
java.lang.reflect.InvocationTargetException

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

 at java.lang.reflect.Method.invoke(Method.java:597)

Caused by: java.lang.UnsupportedClassVersionError: Button1 : Unsupported major.minor version 51.0
...


So I went back to Eclipse, compiled the project with the right JDK version (1.6), and finally the command was there!

Thanks a lot for your help, very appreciated
Alberto
0 Kudos