• Register
0 votes
167 views

Problem :

Everytime we compile the GUI , we get bellow error

exception in thread "javafx application thread" java.lang.nullpointerexception

by (6.9k points)  

1 Answer

0 votes

Solution:

My advise would be to never initialize variable at the declaration, but do it in constructor, and then check for every nullity possible.

Please refer bellow code:

public class MyClass{

double mycrashRisk;

public MyClass(){
 TDriver id = ...//get id
 if(id == null){
   throw new MyExplicitException();
 }
 mycrashRisk = mycalcRisk(id);
}

Further Readings:

https://github.com/jfoenixadmin/JFoenix/issues/970

by (36.1k points)  
edited by
...