8 @FXML
9 private TextField name;
10 @FXML
11 private TextField dateCreated;12 @FXML
13 private TextField subfolders;
14 @FXML
18 @FXML
19 private TextField editors;
20 @FXML
21 private TextField files;22
23 public void setInfo(String name, String date, String subfolders, String parentFolder, String parentCourse, String editors, String files) {
24 this.name.setText(name);
16 @FXML
17 private TextField parentCourse;
18 @FXML
19 private TextField editors;20 @FXML
21 private TextField files;
22
12 @FXML
13 private TextField subfolders;
14 @FXML
15 private TextField parentFolder;16 @FXML
17 private TextField parentCourse;
18 @FXML
14 @FXML
15 private TextField parentFolder;
16 @FXML
17 private TextField parentCourse;18 @FXML
19 private TextField editors;
20 @FXML
This private field is never initialized before use. This may cause improper behavior at runtime, or even a NullPointerException
.
Check if the logic that uses the field is correct; add an initializer to the declaration or initialize the field at an appropriate point before use.
If a field is not explicitly initialized, Java will set the value of the field to a default value at runtime. This default value depends on the type:
0
(or the floating point equivalent)Object
, the default value is null
.Java does not check if a field is properly initialized in the way it checks local variables, and this can easily prevent one from immediately noticing that something is wrong.
// Never initialized, never assigned a value.
private String internalField;
String someMethod() {
someInternalCode(internalField); // `internalField` will be null!
}
Assign a valid default to the field, or initialize it wherever sensible.
private String internalField = "defaultValue";
// ...
This issue will not be reported for fields marked as being injected (marked with annotations such as @Inject
or @Autowired
).