commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhenyu Lu <zhenyulu2...@yahoo.com>
Subject problem about common configuration
Date Fri, 03 Sep 2004 18:35:23 GMT

hi, I am newbie for common configuration. I use common-configuration1.0rc and jdk1.4.2. My
configuration file is like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<configuration>
  <host> localhost </host>
</configuration>

 

My program is :

public class ServerApp {

  /** Creates a new instance of MainApp */
  public ServerApp() {

  }

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    try {
      Properties props = new Properties();

      ConfigurationFactory factory = new ConfigurationFactory();
      factory.setConfigurationFileName("Config.xml");
      Configuration config = factory.getConfiguration();
      /** These properties pertain to setting up a TCP link */
      String host = config.getString("host");
      System.out.println(host);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

I got a exception:

java.util.NoSuchElementException: 'host' doesn't map to an existing object
 at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:890)


Did I do someting wrong? I tried :

String host = config.getString("Configuration.host");

String host = config.getString("Configuration[0].host");

neither works. 

Any idea? Thanks.


 


 

		
---------------------------------
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message