config.getString() Returns Null

Discussion in 'Plugin Development' started by xXxAdmanxXx, Jul 24, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    xXxAdmanxXx

    Hello!

    I cant seem to figure out why the following lines of code return null:

    Even though VAR + ".short_name" exists (I know because I'm inputting the var, and setline2 and setline3 both return as they should) it will refuse to output anything but null!

    My config load is like this (I changed the file path to conceal the name of the plugin in this post):

    Any suggestions? Thanks, all responses will be appreciated!

    ~Ad-man
     
  2. Offline

    Hretsam

    If its returning null because it cant see the nodes.
    Your config should be something like:
    Code:
    <split2>:
         short_name: something
    <split3>:
         short_name: something
    
     
  3. Offline

    Randy Schouten

    You should use getProperty instead of getString.
    It works pretty much all the time that I use it.

    Also, to load a file:
    Code:
    private static final File file = new File("plugins" + File.separator + "MyPlugins" + File.separator + "MyConfig.yml");
        static Configuration config = load();
        public static Configuration load() {
            try {
                Configuration configtemp = new Configuration(file);
                configtemp.load();
                return configtemp;
                }catch (Exception e) {
                    e.printStackTrace();
                }
            return null;
        }
     
  4. Offline

    xXxAdmanxXx

    Ok apparently it cant read the Config at all, no matter if I use your load or my load, yet it finds the file!

    I tried
    to check and both came out null! Any reason this would be happening?
     
  5. Offline

    Randy Schouten

    First, have you read my piece of code? (especially "File.seperator")
    Second, can you show the config?
     
  6. Offline

    Acrobot

    config.load()?
     
  7. Offline

    cholo71796

    I was just about to say this. Make sure you have added the config.load(); line before the ones you posted in the OP.
     
  8. Offline

    xXxAdmanxXx

    Gah, tried changing the position of config.load() closer in the script but still nothing, even if I use Randy's Method or loading and getProperty.

    My config file (First few lines as example, takes up 1000 lines):
    I guess ive given away enough by now to say that it does have something to do with block/item names and signs. lol
     
  9. Offline

    Randy Schouten

    Ah there we go.

    The first node is a number, which doesn't work as far as I know.
    If there's a way to make this possible, someone enlighten me.

    Anyway, try making it "b0", "b1", etc.
    See if that works, if so, that'd be the problem.
     
  10. Offline

    nisovin

    It's probably better to load the config like this:
    Code:
    File file = new File(getDataFolder(), "MyConfig.yml");
    Configuration config = new Configuration(file);
    config.load();
    
    Also, I believe you can have numbers as node names if you put them in quotes.
    Code:
    '0':
         aliases: [ ]
         canonical_name: Air
         short_name: air
     '1':
         aliases: [stone, smoothstone]
         canonical_name: Stone
         short_name: stone
     '2':
         aliases: [grass, grassydirt]
         canonical_name: Grass
         short_name: grass
     
  11. Offline

    xXxAdmanxXx

    Omigawd! Thank you. That helped, we changed it to a B in front of it and it worked! Thank you for all your help!
     
Thread Status:
Not open for further replies.

Share This Page