title: Get Values of variables under an Enum
body: <p>I want to write into a file/print the constants of an enum, as well as the values of their variables.</p>
  
  <p>For example, here is what I thought of doing:</p>
  
  <pre><code>id, field_name_1, field_name_2, ...
  enum_id, field_value_1, field_value_2, ...
  ...
  </code></pre>
  
  <p>However, I am not fully sure on how to do such a thing, as I only recently began working with reflection.</p>
  
  <p>This is the code that I currently have.</p>
  
  <pre><code>public static void writeEnum(String filename, Enum e, SnelPlugin plugin){
          SnelTextFile file = new SnelTextFile(plugin, new File(plugin.getDataFolder() + "/" + filename + ".txt"));
          Logger.debug("Starting an EnumWriter for " + filename + ".txt for plugin " + plugin.getPluginName());
  
      try {
          file.openWriter(true);
  
          Field[] fields = e.getClass().getFields();
  
          // HEADER
          String info = "";
          for(Field f: fields) {
              info += ", " + f.getName();
              Logger.debug("Detected value: " + f.getName());
          }
          info = info.replaceFirst(", ", "");
          file.addLine(info);
  
          // CONTENT
          for(Object current: e.getDeclaringClass().getEnumConstants()){
              Logger.debug(current.toString());
  
              String result = "";
  
              for(Field f: fields){
                  result += ", " + f.get(current);
              }
  
              result = result.replaceFirst(", ", "");
  
              file.addLine(result);
  
              Logger.debug("Added row: " + result);
          }
      }catch (Exception ex){
          ex.printStackTrace();
      }finally {
          try {
              file.closeWriter();
          } catch (IOException e1) {
          }
      }
  
      Logger.log(LColor.GREEN + "Finished an EnumWriter action on " + filename + ".txt from " + plugin.getPluginName());
  }
  </code></pre>
  
  <p>Here is the Enum (APIPerm), which I setup for a simple test:</p>
  
  <pre><code>COMMANDS_SNELAPI,
  COMMANDS_SNELAPI_INFO;
  
  private String id;
  
  APIPerm(){
      id = getID();
  }
  
  @Override
  public String getPrefix() {
      return "snelapi";
  }
  
  @Override
  public String getID(){
      return getPrefix() + "." + this.toString().toLowerCase().replaceAll("_", ".");
  }
  </code></pre>
  
  <p>However, I get an NPE in <code>for(Object current: e.getDeclaringClass().getEnumConstants())</code></p>
  
  <p>Thanks for your help,
  Sneling.</p>