• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

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


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:


by (36.1k points)  
edited by