0

Getting an issue while trying to access bean inside another class . Example code below :

@Component
public class Class1 implements Runnable {

    @Autowired
    private GetStocks getStocks;
    
    private String userName;
    
    public Class1() {
        super();
    }
    
    public Class1(String userName) {
        super();
        this.userName =userName;
    }
        public void run() {
            
            System.out.println(getStocks);
            //NullPointerException
            
        }   
    
}

here we have class1 inside which i'm trying to access the autowired getStocks instance variables but I'm getting the null pointer exception instead . Appreciate all your help

0 Answers0