CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: help!

  1. #1
    Join Date
    May 2011

    Angry help!

    Im trying to make a program that simulates a vending machine while using stacks and queues, but while sending out the method to add the objects into my linked list I keep getting a null pointer exception. heres the code with MachineRow being an interface and FIFO being a linkedList
    public static void loadFIFO(int size, Scanner keyboard, MachineRow FIFO)
    throws FileNotFoundException {
    System.out.print("Enter filename: ");
    String fileopen = keyboard.nextLine();
    Scanner inputFile = new Scanner(new File(fileopen));
    int j = 0;
    while (inputFile.hasNext() && j < size) {
    String name = inputFile.nextLine();
    String type = inputFile.nextLine();
    String upc = inputFile.nextLine();
    VendingProduct add = new Product(name, type, upc);

    and heres the method in the FIFORow class

    public boolean add(VendingProduct product) {
    boolean added=true;
    return added;

    please help if you can!

  2. #2
    Join Date
    Apr 2007

    Re: help!

    1. Use code tags, preserves readable formatting of the code.
    2. Post relevant information. - Stack trace (if any), code samples that shed actual light on your issue.
    3. Please mark to which line of code the exception points to. (eg "<- Exception trown here").
    4. Describe any non-local variables used in your code sample, what is their value when used in a typical test run, and more so, what is their purpose.

    In the code you gave us, there can be roughly a millon things wrong. And without more specific information... why try to extend ones telepathic abilities to quess the surrounding frameworks?

    That said... your handling of Scanner reading is almost certain to fail. Think on the differences in calling next() and nextLine() methods. Think how you can make your file format and its reading more secure. Based on the info you gave me, that would (at least) be a part to re-design.

    Also the boolean returned by our other sample method has absolutely no purpose. Do not do that.

  3. #3
    Join Date
    May 2006

    Re: help!

    My crystal ball has gone on the blink so I'm going to have to guess and my guess is you haven't initialized the FIFOrow variable.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.