• Register
0 votes

Problem :

Everytime we compile the GUI , we get bellow error

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

6 5 3
6,930 points

Please log in or register to answer this question.

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:


9 7 4
38,600 points

Related questions

0 votes
1 answer 114 views
Problem : I am getting bellow error repeatedly exception in thread "awt-eventqueue-0" java.lang.nullpointerexception
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 2 views
Problem: Hello ... Can anyone tell me that why I got this error? exception: java.lang.nullpointerexception ejbclass="productratesservices.getserviceoptions"
asked Apr 1 Ifra 24.4k points
0 votes
1 answer 33 views
0 votes
1 answer 33 views
Hello I'm a new programmer at an high school level as a result I do not know much about programming and am getting quite a few errors which have been resolved while others I completely do not understand.
asked Dec 7, 2020 TeamScript 13.5k points
0 votes
1 answer 78 views
0 votes
1 answer 9 views
Problem: I recently ran into this error in my web application: Java.lang.OutOfMemoryError: PermGen space This is a typical Hibernate / JPA + IceFaces / JSF application running on Tomcat 6 and JDK 1.6. Apparently this can happen after remapping an app a few times.
asked Feb 15 sasha 16.2k points
0 votes
1 answer 12 views
Problem: What are null pointer exceptions, what causes them in general, and how do you trace the cause so that you can fix them?
asked Feb 27 sasha 16.2k points
1 vote
1 answer 47 views
Problem: I was working with Java array. Suddenly I got this error message, “exception in thread "main" java.lang.nullpointerexception”. Can somebody help me out urgently, please? I am attaching the declaring part of my code below for your better understanding. Thanks in advance. import ... + n[i]; //percentage = first * second * third * fourth * fifth * sixth * seventh * 100 / 700; }
asked Mar 6, 2020 Gavin 15.3k points
0 votes
1 answer 2 views
Problem: any ideas on what i need to do for this problem? Exception in thread "javafx application thread"
asked Apr 4 Rohit kr 16.2k points
0 votes
1 answer 223 views
Problem : I am trying to run my registration jsp page with the servlet. But it is throwing following error: The server encountered an internal error that prevented it from fulfilling this request. java.lang.NullPointerException com.java.task11.utils.ValidateUtil.EmailVal( ... .tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:62) I am unable to figure out why this is happening? Any clues?
asked Dec 2, 2019 alecxe 7.5k points