Empty quotation marks in config throw a NullPointerException

Discussion in 'Plugin Development' started by Reflxction, May 3, 2018.

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

    Reflxction

    Hello.
    I'm having a little problem. In my plugin, there's a string in the config that will be saving 6-digit numbers as IDs of tickets. When the plugin generates for the first time, this is definitely going to be empty. Now, when I try to get this string so I can add or remove IDs from it, I get a NPE every time I attempt to get it. Attempting to fix this I made it "." instead of being "", but I really find this ugly and it will probably rise bugs in the future due to things like cant parse number etc. Any way to avoid that? I was thinking of using try/catch for that but I'm not entirely sure how. Thanks for the help.

    P.S: My config looks like this:
    Code:
    Tickets:
      List: ""
     
  2. Online

    timtower Administrator Administrator Moderator

    @xTechno_ Can you make an example config of how it will be?
     
  3. Offline

    Reflxction

    After someone creates a ticket, for example, with the ID 312822, it'll be like that
    Code:
    Tickets:
      List: "312822"
      '312822':
        Sender: "dfbd02a4-6be1-4153-a203-aed7204d35b6"
        Description: 'some example ticket'
        Closed: false
     
  4. Online

    timtower Administrator Administrator Moderator

    @xTechno_ Why do you even need the list variable?
    You can do getConfig().getConfigurationSection("Tickets").getKeys(false)
    Then you get all child nodes.
    Not to mention that your current method only holds a single string, not a list or number
     
Thread Status:
Not open for further replies.

Share This Page