Getting java.lang.NullPointerException error when assigning values to an array of user-defined class
<p>I'm trying to create a simple JavaFX application that switches between 2 screens, one where you can change the variables stored and one that just displays, I have a function defined in the main method that just returns a nullpointerexception when compiling the project in the error log it says its on the line that reads</p>

<pre><code>taskList[i].setTaskName(taskNames[i]);
</code></pre>

<p>I tried adding an if statement, similar to the one for the section for the getTechAssigned method, because this variable will be constantly changing, while the taskName variable will be unchanged. I'm just not sure why it's coming up, here's the full code: </p>

<p>variable declarations</p>

<pre><code>Button assignTask, finalizeTask;
    FlowPane pane1, pane2;
    Scene scene1, scene2;
    Stage theStage;
    String[] taskNames = {"Notes", "Paging", "Event Mgmt - Early", 
                          "Event Mgmt -Late", "Airhub 2DA", "Airhub 1DA"
                          "GSSD", "GSSI", "GSSRR", "Publishing",
                          "Check Holdovers", "Radio", "PTI Walkoff", "Phones
                          1300"};
    task[] taskList = new task[taskNames.length];
    GridPane taskGrid = new GridPane();
</code></pre>

<p>function that is causing the error:</p>

<pre><code>public void initializeTasks() {
    for (int i = 0; i &lt; taskList.length; i++) {
        taskList[i].setTaskName(taskNames[i]);
        Text t = new Text(taskList[i].getTaskName());
        taskGrid.setRowIndex(t, i);
        taskGrid.setColumnIndex(t, 0);

        if(taskList[i].getTechAssigned() == null) {
            taskList[i].setTechAssigned("Not Assigned");
            }

        Text r = new Text(taskList[i].getTaskName());
        taskGrid.setRowIndex(r, i);
        taskGrid.setColumnIndex(r, 1);
        }

    }
</code></pre>