Why am I getting NullPointerException here
Package Threads ; Public Class Test Applications Runnabal {FF D; Public static zero main (string [] args) {new test (). Go (); } Go to zero () {System.out.println (Thread.currentThread ()); D = new FF (); New thread (new test) Start (); New thread (new test) Start (); } Public Zero Run () {System.out.println (d); Println (Thread.currentThread ()); D.chat (Thread.currentThread (.) GetId ()); // RTE}} square FF {static long flag = 0; Zero chat (long id) {if (flag == 0) {flag = id; } For (int x = 1; x & lt; 3; x ++) {if (flag == ID) {System.out.println ("yo"); } And {System.out.println ("friend"); }
// Anyone can explain why I am getting NullPointerException here. Although the d
reference variable was intialized in go ()
method but I think there is something to do that when the new thread is created.
d
is an example field for class test
. Starting it for a frequency of test
is not started for all instances which are created later. You started this code in the example go
method created in main
. But after that, you can create examples of new the test
for which their area has not been started:
New thread (New test). Start (); // The new Test () object has not been started for New Thread (New Test ()).
The field is in a solution maker:
public testing () {d = new FF (); }
Comments
Post a Comment