java.lang.NullPointerException Problem

Discussion in 'Plugin Development' started by JND_3004, Oct 20, 2016.

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

    JND_3004

    Hi guys,

    i have a little Problem. I become the error:
    Code:
    Caused by: java.lang.NullPointerException
            at me.jdittmer.PlayerReport.PlayerReport.onCommand(PlayerReport.java:161) ~[?:?]
    I will report a player with the command /pr r JND_3004 Hacking. The report arraylist should add in a reports.yml.
    With .set(); works .. but only for the first report, the second report will not saved in the file, but why?

    A short snipped of my code:
    Code:
                                List<String> player_report_list = new ArrayList<String>();
                                player_report_list.add(reportTime());            // Datum
                                player_report_list.add(""+sender);                // Von
                                player_report_list.add(args[1]);                // An
                                player_report_list.add(args[2]);                // Grund
                                player_report_list.add("false");                // Betreuer?
                                player_report_list.add(null);                    // Betreuer, falls ja
                               
                                ReportConfigs.set("playerReports.reports.159", player_report_list);
    The last line make the error.
    Hope you can help me, and sorry for my bad english :/
     
  2. Offline

    Zombie_Striker

    We can't help you with this because we do not know what line 161 is. The reason you are getting this error is because some variable is null on this line. Go through all the variables and find out which one is null.

    That is because you are overriding the last result.
    I think this bold part is the issue. You are not incrementing this variable, so you are overriding existing reports instead of creating new ones. Save the last report ID somewhere and add +1 to the number every time you create a report.

    BTW: This will only support one word. If you want to support multiple words you will need to use a StringBuilder to combine the rest of the args.
     
Thread Status:
Not open for further replies.

Share This Page