0

This is my code. It thinks that the config area section = null.

Heres the code:

public void loadArenas() {

    fc1 = new File(plugin.getDataFolder(), "config.yaml");

    if (!fc1.exists()) {
        try {
            fc1.createNewFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    fc = YamlConfiguration.loadConfiguration(fc1);

    for (String keys : fc.getConfigurationSection("Arenas.").getKeys(false)) {

Oh and heres the error:

Error

3
  • wich one is the line 224? Commented Apr 1, 2014 at 15:30
  • It thinks that the config area section = null. If there's an NPE, then it IS null. You shouldn't argue with the JVM, but find the source of the problem. Commented Apr 1, 2014 at 15:30
  • I suggest you print out the contents of fc or look at your file and verify whether that section exists. If the config file doesn't exist, you create a new one, but I don't see any sort of pre-populating going on. So if you DO create a new one, then I expect the section to not exist. Commented Apr 1, 2014 at 15:34

2 Answers 2

1

fc1 is initialized, but fc is not.

Sign up to request clarification or add additional context in comments.

11 Comments

It all works. Fc is intialized but its the "getConfigurationSection"
@user3482764 so what is the problem? if you know what is null, why don't you fix your code?
I'm asking because I don't know how to fix it.
@user3482764 Why do you think getConfigurationSection is the problem? Or rather, what is wrong with it?
Because thats where the npe leads to
|
0

You should print out the contents of fc1 at the top. It is very likely that you are running into path-related issues and so a new, EMPTY, configuration file is created.

That new file is then used as the input to fc, and naturally the "Arenas." section wouldn't exist. The NPE would either be thrown when you try to access the non-existent section's keys via getKeys().

Either way, if you are not sure what the problem is, you can either step through it with a debugger or just throw print statements everywhere to determine that things are what you expect.

9 Comments

I'll try add defaults :) Could you possibly give me the code to add the defaults please?
That doesn't solve the problem. If you're always creating a fresh config file with default settings, that pretty much defeats the purpose of using a config file.
I'll try create the Defaults and if this works, you've saved me.
Doesn't work, still says the fc1 = new File(plugin.getDataFolder(), "config.yml"); is a problem :(((
I thought you said getConfigurationSection was the problem? Were you providing incorrect information the whole time?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.