title: Problems reading an ini file in Java
body: <p>I am having trouble using Apache commons configuration to read an ini file. I attached the imports incase I am missing something. Below is an example I found on stackoverflow, and as far as I can find, there are no other examples to look at. The problem is <code>iniObj</code>. Using Eclipse it is highlighted in red. </p>
  
  <p>If I initialize the variable, <code>new "HierarchicalINIConfiguration(iniFile);</code> gets angry and wants to add a try/catch or throws... which should be no problem... but then the try/catch or throws gets angry and says "No exception of type ConfigurationException can be thrown; an exception type must be a subclass of Throwable." </p>
  
  <p>Which then brought me to <a href="https://stackoverflow.com/questions/2416980/configurationexception-in-java">this question</a>. I added the commons lang 3.1. I have commons config 1.9, commons collections 3.2.1. commons logging 1.1.1 as well. I have also tried this with commons config 1.8 and lang 2.6. Now I get a new error "Exception in thread "main" java.lang.NullPointerException at com.toolbox.dev.ReadIni.main(ReadIni.java:28)" You can see the new code below after the adjustments I made to try and resolve the errors.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>import java.util.Iterator;
  import java.util.Set;
  
  import org.apache.commons.configuration.ConfigurationException;
  import org.apache.commons.configuration.HierarchicalINIConfiguration;
  import org.apache.commons.configuration.SubnodeConfiguration;
  
  public static void main(String[] args) throws ConfigurationException {
      String iniFile = "file.ini";
      HierarchicalINIConfiguration iniConfObj = new HierarchicalINIConfiguration(iniFile);
  
      // Get Section names in ini file
      Set setOfSections = iniConfObj.getSections();
      Iterator sectionNames = setOfSections.iterator();
  
      while(sectionNames.hasNext()) {
          String sectionName = sectionNames.next().toString();
  
          HierarchicalINIConfiguration iniObj = null;
          SubnodeConfiguration sObj = iniObj.getSection(sectionName);
          Iterator it1 = sObj.getKeys();
  
          while (it1.hasNext()) {
              // Get element
              Object key = it1.next();
              System.out.print("Key " + key.toString() +  " Value " +
                sObj.getString(key.toString()) + "\n");
          }
      }
  }
  </code></pre>
  
  <p><strong>Original code from Stack Overflow:</strong></p>
  
  <pre><code>import java.util.Iterator;
  import java.util.Set;
  
  import org.apache.commons.configuration.HierarchicalINIConfiguration;
  import org.apache.commons.configuration.SubnodeConfiguration;
  
  
  public class ReadIni {
  
      public static void main(String[] args) {
          String iniFile = "";
          HierarchicalINIConfiguration iniConfObj = new HierarchicalINIConfiguration(iniFile);
  
          // Get Section names in ini file
          Set setOfSections = iniConfObj.getSections(); 
          Iterator sectionNames = setOfSections.iterator(); 
  
          while(sectionNames.hasNext()) {
  
              String sectionName = sectionNames.next().toString();
              SubnodeConfiguration sObj = iniObj.getSection(sectionName);
              Iterator it1 = sObj.getKeys();
  
              while (it1.hasNext()) {
                  // Get element 
                  Object key = it1.next(); 
                  System.out.print("Key " + key.toString() +  " Value " +
                    sObj.getString(key.toString()) + "\n");
              }
          }
  </code></pre>