title: Get whether laptop is in charging [in ACLine] or not [not in ACLine] in Windows 7?
body: <p>I am using <strong>Netbeans IDE 7.4</strong>.
  I tried with the below code, but I am getting error when trying to execute. Compilation is OK.</p>
  
  <p>Before starting, I have downloaded <a href="https://maven.java.net/content/repositories/releases/net/java/dev/jna/jna/3.5.1/jna-3.5.1.jar" rel="nofollow">jna-3.5.1.jar</a> and added [Right-click "Libraries" >> "Add JAR/Folder..."] in my project.</p>
  
  <p>Below is the code:</p>
  
  <pre><code>    package battery;
  
  import java.util.ArrayList;
  import java.util.List;
  import com.sun.jna.Native;
  import com.sun.jna.Structure;
  import com.sun.jna.win32.StdCallLibrary;
  
  public class Battery implements Kernel32{
      public static void main(String[] args){
          try{
              Kernel32.SYSTEM_POWER_STATUS batteryStatus = new Kernel32.SYSTEM_POWER_STATUS();
              Kernel32.INSTANCE.GetSystemPowerStatus(batteryStatus);
  
              System.out.println(batteryStatus); // Shows result of toString() method.
          }
          catch(Exception ex){System.out.println("Error:\n" + ex);}
      }
  
      @Override
      public int GetSystemPowerStatus(SYSTEM_POWER_STATUS result){
          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
      }
  }
  
  interface Kernel32 extends StdCallLibrary{
      public Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("Kernel32", Kernel32.class);
  
      /**
       * @see http://msdn2.microsoft.com/en-us/library/aa373232.aspx
       */
      public class SYSTEM_POWER_STATUS extends Structure{
          public byte ACLineStatus;
          public byte BatteryFlag;
          public byte BatteryLifePercent;
          public byte Reserved1;
          public int BatteryLifeTime;
          public int BatteryFullLifeTime;
  
          @Override
          protected List&lt;String&gt; getFieldOrder(){
              ArrayList&lt;String&gt; fields = new ArrayList&lt;String&gt;();
              fields.add("ACLineStatus");
              fields.add("BatteryFlag");
              fields.add("BatteryFullLifeTime");
              fields.add("BatteryLifePercent");
              fields.add("BatteryLifeTime");
              fields.add("Reserved1");
              return fields;
          }
  
          /**
           * The AC power status
           */
          public String getACLineStatusString(){
              switch (ACLineStatus){
                  case (0): return "Offline";
                  case (1): return "Online";
                  default: return "Unknown";
              }
          }
  
          /**
           * The battery charge status
           */
          public String getBatteryFlagString(){
              switch (BatteryFlag){
                  case (1): return "High, more than 66 percent";
                  case (2): return "Low, less than 33 percent";
                  case (4): return "Critical, less than five percent";
                  case (8): return "Charging";
                  case ((byte) 128): return "No system battery";
                  default: return "Unknown";
              }
          }
  
          /**
           * The percentage of full battery charge remaining
           */
          public String getBatteryLifePercent(){
              return (BatteryLifePercent == (byte) 255) ? "Unknown" : BatteryLifePercent + "%";
          }
  
          /**
           * The number of seconds of battery life remaining
           */
          public String getBatteryLifeTime(){
              return (BatteryLifeTime == -1) ? "Unknown" : BatteryLifeTime + " seconds";
          }
  
          /**
           * The number of seconds of battery life when at full charge
           */
          public String getBatteryFullLifeTime(){
              return (BatteryFullLifeTime == -1) ? "Unknown" : BatteryFullLifeTime + " seconds";
          }
  
          @Override
          public String toString(){
              StringBuilder sb = new StringBuilder();
              sb.append("ACLineStatus: " + getACLineStatusString() + "\n");
              sb.append("Battery Flag: " + getBatteryFlagString() + "\n");
              sb.append("Battery Life: " + getBatteryLifePercent() + "\n");
              sb.append("Battery Left: " + getBatteryLifeTime() + "\n");
              sb.append("Battery Full: " + getBatteryFullLifeTime() + "\n");
              return sb.toString();
          }
      }
  
      /**
       * Fill the structure.
       */
      public int GetSystemPowerStatus(SYSTEM_POWER_STATUS result);
  }
  </code></pre>
  
  <p>Below is the error encountered:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Could not access instance of interface battery.Kernel32 (java.lang.IllegalAccessException: Class com.sun.jna.Native can not access a member of class battery.Kernel32 with modifiers "public static final")
  </code></pre>