title: Reading windows logs using jna
body: <h1>I am getting an exception while reading windows logs using jna</h1>
  <p>Following is the program, I am using to read the logs. I took this program from another post.</p>
  <pre><code>import java.io.IOException;
  import java.nio.ByteBuffer;
  import java.nio.CharBuffer;
  import java.util.Arrays;
  
  import com.sun.jna.*;
  import com.sun.jna.platform.win32.*;
  import com.sun.jna.platform.win32.WinNT.*;
  import com.sun.jna.ptr.IntByReference;
  
  public class Test {
  
  public static void main(String[] args) throws NumberFormatException, IOException {
  
      HANDLE h = com.sun.jna.platform.win32.Advapi32.INSTANCE.OpenEventLog(null, &quot;Application&quot;);
      IntByReference pnBytesRead = new IntByReference();
      IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
  
      IntByReference pOldestRecord = new IntByReference();
      assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.GetOldestEventLogRecord(h,  pOldestRecord));
      int dwRecord = pOldestRecord.getValue();
      System.out.println(&quot;OLD: &quot; + dwRecord);
      IntByReference pRecordCount = new IntByReference();
      assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, pRecordCount));
      int dwRecordCnt = pRecordCount.getValue();
      System.out.println(&quot;CNT: &quot; + dwRecordCnt);
  
      int bufSize = 0x7ffff; //(r.size()) * 2048;
      Memory buffer = new Memory(bufSize);
      int rc = 0;
      int cnt = 0;
      while(com.sun.jna.platform.win32.Advapi32.INSTANCE.ReadEventLog(h, 
              WinNT.EVENTLOG_SEEK_READ  /*
              | WinNT.EVENTLOG_SEQUENTIAL_READ */ 
              | WinNT.EVENTLOG_FORWARDS_READ /*
              | WinNT.EVENTLOG_BACKWARDS_READ*/
              , 
              dwRecord, buffer, 
              bufSize, 
              pnBytesRead, 
              pnMinNumberOfBytesNeeded)) {
  
          rc = Kernel32.INSTANCE.GetLastError();
          if (rc == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
              break;
          }        
  
          int dwRead = pnBytesRead.getValue();
          Pointer pevlr = buffer;
  
          while (dwRead &gt; 0) 
          {
              cnt++;
              EVENTLOGRECORD record = new EVENTLOGRECORD(pevlr);
              System.out.println(&quot;------------------------------------------------------------&quot;);
              System.out.println(cnt+&quot;. &quot; + dwRecord + &quot; Event ID: &quot; + record.EventID.shortValue() + &quot; SID: &quot; + record.UserSidLength);
  
              dwRecord++;
  
              // WCHAR SourceName[]
              // WCHAR Computername[]
              {
                  ByteBuffer names = pevlr.getByteBuffer(record.size(), 
                          (record.UserSidLength.intValue() != 0 ? record.UserSidOffset.intValue() : record.StringOffset.intValue()) - record.size());
                  names.position(0);
                  CharBuffer namesBuf = names.asCharBuffer();
                  String[] splits = namesBuf.toString().split(&quot;\0&quot;);
                  System.out.println(&quot;SOURCE NAME: \n&quot; + splits[0]);
                  System.out.println(&quot;COMPUTER NAME: \n&quot; + splits[1]);
              }
              // SID   UserSid
              if (record.UserSidLength.intValue() != 0){
                  ByteBuffer sid = pevlr.getByteBuffer(record.UserSidOffset.intValue(), record.UserSidLength.intValue());
                  sid.position(0);
                  //CharBuffer sidBuf = sid.asCharBuffer();
                  byte[] dst = new byte[record.UserSidLength.intValue()];
                  sid.get(dst);
                  System.out.println(&quot;SID: \n&quot; + Arrays.toString(dst));
              }
              else {
                  System.out.println(&quot;SID: \nN/A&quot;);
              }
              // WCHAR Strings[]
              {
                  ByteBuffer strings = pevlr.getByteBuffer(record.StringOffset.intValue(), record.DataOffset.intValue() - record.StringOffset.intValue());
                  strings.position(0);
                  CharBuffer stringsBuf = strings.asCharBuffer();
                  System.out.println(&quot;STRINGS[&quot;+record.NumStrings.intValue()+&quot;]: \n&quot; + stringsBuf.toString());
              }
              // BYTE  Data[]
              {
                  ByteBuffer data = pevlr.getByteBuffer(record.DataOffset.intValue(), record.DataLength.intValue());
                  data.position(0);
                  CharBuffer dataBuf = data.asCharBuffer();
                  System.out.println(&quot;DATA: \n&quot; + dataBuf.toString());
              }
              // CHAR  Pad[]
              // DWORD Length;
  
              dwRead -= record.Length.intValue();
              pevlr = pevlr.share(record.Length.intValue());
          }
      }
      assertTrue(rc == W32Errors.ERROR_HANDLE_EOF);
      assertTrue(com.sun.jna.platform.win32.Advapi32.INSTANCE.CloseEventLog(h));        
  }
  
  
  private static void assertTrue(boolean getOldestEventLogRecord) {
  
  }
  </code></pre>
  <p>}</p>
  <p>The Exception is as follows :-</p>
  <pre><code>    Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: com.sun.jna.IntegerType.
      &lt;init&gt;(IJZ)V
      at com.sun.jna.platform.win32.WinDef$DWORD.&lt;init&gt;(WinDef.java:57)
      at com.sun.jna.platform.win32.WinDef$DWORD.&lt;init&gt;(WinDef.java:53)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at com.sun.jna.NativeMappedConverter.defaultValue(NativeMappedConverter.java:47)
      at com.sun.jna.NativeMappedConverter.&lt;init&gt;(NativeMappedConverter.java:41)
      at com.sun.jna.NativeMappedConverter.getInstance(NativeMappedConverter.java:29)
      at com.sun.jna.Structure.calculateSize(Structure.java:803)
      at com.sun.jna.Structure.useMemory(Structure.java:254)
      at com.sun.jna.Structure.useMemory(Structure.java:238)
      at com.sun.jna.Structure.&lt;init&gt;(Structure.java:174)
      at com.sun.jna.Structure.&lt;init&gt;(Structure.java:167)
      at com.sun.jna.Structure.&lt;init&gt;(Structure.java:163)
      at com.sun.jna.platform.win32.WinNT$EVENTLOGRECORD.&lt;init&gt;(WinNT.java:1789)
      at Test.main(Test.java:54)
  </code></pre>
  <p>Please help me out from the trouble. Thanks a lot in advance. I am new to this great site so, please excuse me for bad explanation</p>