FATAL ERROR in native method (Excel)

Help
Adrian
2012-03-23
2013-05-20
  • Adrian

    Adrian - 2012-03-23

    Hi Folks,

    i'm using Jacob 1.17-M2 in maven and testNG other eclipse. Currently small Excel changes will work fine. but i couldn't close the application. One Instance allways open. Have a look at my Code:

            ComThread.InitMTA(true);
            ActiveXComponent oExcel = new ActiveXComponent("Excel.Application");
            oExcel.setProperty("Visible", new Variant(true));

            System.out.println("version=" + oExcel.getProperty("Version"));

            oExcel.setProperty("Visible", new Variant(false));
            Dispatch workbooks = oExcel.getProperty("Workbooks").toDispatch();
            Dispatch workbook = Dispatch.call(workbooks, "Open", "C:\\workspace\\J2Com\\src\\main\\resources\\testNative.xls").toDispatch();
            Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();

            Dispatch worksheets = Dispatch.get(workbook, "WorkSheets").toDispatch();
            int sheetcount = Integer.parseInt(Dispatch.call(worksheets, "Count").toString());

            Dispatch a1 = Dispatch.invoke((Dispatch) sheet, "Range", Dispatch.Get, new Object { "A1" }, new int).toDispatch();
            Dispatch b1 = Dispatch.invoke((Dispatch) sheet, "Range", Dispatch.Get, new Object { "B1" }, new int).toDispatch();
            Dispatch c1 = Dispatch.invoke((Dispatch) sheet, "Range", Dispatch.Get, new Object { "C1" }, new int).toDispatch();

            Dispatch sheet2 = Dispatch.get(workbook, "ActiveSheet").toDispatch();

            Dispatch a12 = Dispatch.invoke((Dispatch) sheet2, "Range", Dispatch.Get, new Object { "A1" }, new int).toDispatch();

            Dispatch.put((Dispatch) a1, "Value", "123");
            Dispatch.put((Dispatch) b1, "Value", "123");
            Dispatch.put((Dispatch) a12, "Value", "123");

            System.out.println("a1 from excel:" + Dispatch.get((Dispatch) a1, "Value"));
            System.out.println("b1 from excel:" + Dispatch.get((Dispatch) b1, "Value"));
            System.out.println("c1 from excel:" + Dispatch.get((Dispatch) c1, "Value"));
            System.out.println("a12 from excel:" + Dispatch.get((Dispatch) a12, "Value"));

            Variant f = new Variant(false);
            Dispatch.call((Dispatch) workbook, "Close", f);
            ComThread.Release();

    Now i have an FATAL ERROR after execute this Code. Just look:

    Running:
      C:\Users\991721\AppData\Local\Temp\testng-eclipse-356815576\testng-customsuite.xml

    main: Loading library jacob-1.17-M1-x64 using System.loadLibrary
    main: Loading library jacob-1.17-M1-x64 using System.loadLibrary
    main: Loading library jacob-1.17-M1-x64 using System.loadLibrary
    main: ComThread: before Init: 0
    main: ComThread: after Init: 0
    main: Loading library jacob-1.17-M1-x64 using System.loadLibrary
    main: ROT: Automatic GC flag == true
    main: ComThread: after ROT.addThread: 0
    Thread-1: ComThread: before Init: 2
    Thread-1: ComThread: after Init: 2
    Thread-1: ROT: Automatic GC flag == true
    Thread-1: ComThread: after ROT.addThread: 2
    main: ROT: adding com.jacob.activeX.ActiveXComponent@4430d82d->com.jacob.activeX.ActiveXComponent table size prior to addition:0
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:1
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:2
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:3
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:4
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:5
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:6
    version=12.0
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:7
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:8
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:9
    main: ROT: adding com.jacob.com.Dispatch@6f25844f->com.jacob.com.Dispatch table size prior to addition:10
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:11
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:12
    main: ROT: adding com.jacob.com.Dispatch@7426dbec->com.jacob.com.Dispatch table size prior to addition:13
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:14
    main: ROT: adding com.jacob.com.Dispatch@4cf7c31d->com.jacob.com.Dispatch table size prior to addition:15
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:16
    main: ROT: adding com.jacob.com.Dispatch@bd10a5c->com.jacob.com.Dispatch table size prior to addition:17
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:18
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:19
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:20
    main: ROT: adding com.jacob.com.Dispatch@6d3f7281->com.jacob.com.Dispatch table size prior to addition:21
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:22
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:23
    main: ROT: adding com.jacob.com.Dispatch@487a1576->com.jacob.com.Dispatch table size prior to addition:24
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:25
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:26
    main: ROT: adding com.jacob.com.Dispatch@44050988->com.jacob.com.Dispatch table size prior to addition:27
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:28
    main: ROT: adding com.jacob.com.Dispatch@2d8941f7->com.jacob.com.Dispatch table size prior to addition:29
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:30
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:31
    main: ROT: adding com.jacob.com.Dispatch@3ba42792->com.jacob.com.Dispatch table size prior to addition:32
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:33
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:34
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:35
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:36
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:37
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:38
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:39
    a1 from excel:123.0
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:40
    b1 from excel:123.0
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:41
    c1 from excel:null
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:42
    a12 from excel:123.0
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:43
    main: ROT: adding ->com.jacob.com.Variant table size prior to addition:44
    main: ComThread: before clearObjects
    main: ROT: 2 thread tables exist
    main: ROT: 45 objects to clear in this thread's ROT
    main: ROT: removing 1798675483->com.jacob.com.Variant
    main: Variant: 1798675483 don't want to release a constant
    main: ROT: removing 308587341->com.jacob.com.Variant
    main: SafeRelease: com.jacob.com.Variant
    main: ROT: removing 1656788308->com.jacob.com.Variant
    main: Variant: 1656788308 don't want to release a constant
    main: ROT: removing 55821173->com.jacob.com.Variant
    main: SafeRelease: com.jacob.com.Variant
    main: ROT: removing 763970039->com.jacob.com.Dispatch
    main: SafeRelease: com.jacob.com.Dispatch
    FATAL ERROR in native method: Field type (instance) mismatch in JNI get/set field operations
    at com.jacob.com.Dispatch.release(Native Method)
    at com.jacob.com.Dispatch.safeRelease(Dispatch.java:250)
    at com.jacob.com.ROT.clearObjects(ROT.java:171)
    at com.jacob.com.ComThread.Release(ComThread.java:128)
    - locked <0x00000000bd7d5488> (a java.lang.Class for com.jacob.com.ComThread)
    at TestExcel.TestExcelService.testCloseExcelNativeJacob(TestExcelService.java:61)
    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)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:758)
    at org.testng.TestRunner.run(TestRunner.java:613)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
    at org.testng.TestNG.run(TestNG.java:974)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)

    Could somebody explain me why it isn't possible to Close the Application(Excel). I  have check more solutions that i found in this forum but nothing works correctly.

    i hope
    Adrian

     
  • Adrian

    Adrian - 2012-03-23

    i have forget that it is Excel 2007 (12.0.6654.5003) SP3 MSO (12.0.6607.1000) on a i5 Intel 64Bit.

     
  • shutear

    shutear - 2012-03-23

    First I'm sorry to say that I can't help you,but can you tell me how you config your application ,and whether or not you meet an exception as follow:"java.lang.IllegalStateException: Can't find META-INF/JacobVersion.properties using       JacobReleaseInfo.class.getClassLoader().getResourceAsStream()".
    Thanks a lot!

     
  • shutear

    shutear - 2012-03-23

    Does your application have the "META-INF/JacobVersion.properties" file? And I use the latest version.
    Thanks!

     
  • Adrian

    Adrian - 2012-03-23

    now it works fine with 1.16, thanks

     
  • Anonymous

    Anonymous - 2012-03-29

    Date una vuelta por este blog… http://blog.163.com/qcb_163/blog/static/95454664201222410050258/
    Te indican bien clarito como resolverlo.

    Solo tienes que crear un archivo JacobVersion.properties en el directorio META-INF del proyecto con el contenido siguiente

    #Sat Feb 26 16:51:16 EST 2005
    version=1.16
    build.date=26-February-2012 16\:51\:16
    build.iteration=101

     
  • clay_shooter

    clay_shooter - 2012-04-25

    The new 1.16.1 version should fix the JacobVersion.properties problem.  It was inadvertently not included in 1.16 and 1.17-M1

     
  • clay_shooter

    clay_shooter - 2012-04-25

    Did you call "Quit" to terminate the instance?  I think "Close" just closes the workbook.

     

Log in to post a comment.