Showing results for 
Search instead for 
Do you mean 
Reply

JAVA:Error as NXOpen User Function - Works from Command line

Hi there,

when I am executing the .class file of this java code as NXOpen User Function (File-> Execute-> NXopen...):

 

package testproject;

//
import java.io.File;
import nxopen.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;

public class Test
{
  public static void main(String [] args) throws Exception
  {

     String xls_path = "C:\\MASTER.xls";
       NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(xls_path));
       HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), true);

        wb.close();
        fs.close();

  }
  
  public static final int getUnloadOption() { return nxopen.BaseSession.LibraryUnloadOption.IMMEDIATELY; }
  
}

 

I am getting the error: "A JAVA exception was encountered" in NX. When I am running the .class file from command line - it works great. What am I doing wrong ?

Thanks in advance !

1 REPLY

Re: JAVA:Error as NXOpen User Function - Works from Command line

 

You could try getting the NX session.  I realize you are not actually calling any NX Open methods, but maybe NX wants you to get the session when you run interactively.  I don't know for sure whether it will make a difference, but it would be a simple test.