• Register
0 votes
439 views

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

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

9 7 4
38,600 points

Related questions

0 votes
1 answer 103 views
103 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 13 views
13 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 10.1k points
0 votes
1 answer 46 views
1 vote
1 answer 42 views
42 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
0 votes
1 answer 4 views
4 views
Please help me.
asked 2 days ago TeamScript 10.1k points
0 votes
1 answer 5 views
5 views
Thank you in advance for any help?
asked Jan 5 TeamScript 10.1k points
0 votes
1 answer 8 views
8 views
Help me by solving this problem.
asked Jan 2 TeamScript 10.1k points
0 votes
1 answer 11 views
11 views
I know the problem lies with the recursion.
asked Jan 2 TeamScript 10.1k points
0 votes
1 answer 9 views
9 views
Who can help me to solve this problem?
asked Dec 28, 2020 TeamScript 10.1k points