0

Would anyone please explain why I am getting this error? Not just this one

Constructor 'StockMachine(java.lang.String)' is never used

but also one that says Method is never used. I am not entirely sure why this is happening. Here is a snippet of my code:

import java.io.*;
import java.util.*;
import java.io.FileInputStream;

public class StockMachine {

    private StockPriceService [] stockPriceServices;

    private String tickerSymbols[];

    private final int NUMBEROFSERVICES = 3;

    public StockMachine(String fileName) {
        stockPriceServices = new StockPriceService[3];
        stockPriceServices[0] = new UHStockService();
        stockPriceServices[1] = new NLPService();
        stockPriceServices[2] = new ExternalService();
        try {
            FileInputStream fis = new FileInputStream(fileName);
            Scanner scan = new Scanner(fis);
            this.tickerSymbols = new String[scan.nextInt()];
            int i = 0;
            while (scan.hasNext()) {
                this.tickerSymbols[i] = scan.next();
                i++;
            }
        }

        catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
redben
  • 5,578
  • 5
  • 47
  • 63
Anegl
  • 1
  • 1
  • 1
    That is not an error. That is a warning to tell you that you are not using a part of code you created. – GBlodgett Nov 15 '18 at 01:10
  • That's not an error. The IDE is just warning you that you are never using some of your code. If you intend for other code to use it, then it's not a problem. Unused code can be a indicator of a bug though, so it's good to check those warnings. – Carcigenicate Nov 15 '18 at 01:10
  • @Carcigenicate Ah that makes sense. I thought it was an error my apologies. Whenever I do run it though I get "java.lang.NullPointerException". I figured it was due to that since it is not being used. But I also don't know if what test the codes it gets used there. Thank you though Im now aware it is a warning rather than an error – Anegl Nov 15 '18 at 01:15
  • For the NullPointerException, read https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it. You're likely using an uninitialized variable somewhere; although it's not obvious where from the code you posted. – Carcigenicate Nov 15 '18 at 01:20
  • **But** why would it say that the `public` constructor` was not being used - did I read this wrong? – Scary Wombat Nov 15 '18 at 01:20
  • @ScaryWombat yes its the public one not being used not entirely sure. – Anegl Nov 15 '18 at 01:31
  • @Carcigenicate I have been looking to see where that might have happened , but I am still clueless. I have my code I didn't post the entire thing, as I did not want to make it extremely lengthy. I figured it would be unnecessary. – Anegl Nov 15 '18 at 01:32
  • @Anegl Would you please post `StockPriceService ` class so that we can have clear insight? – Abhinav Nov 15 '18 at 07:12

0 Answers0