Java Doesn't Recognize Something That Exists?

I'm writing an XML checker for a homework assignment. I'm using a stack which uses a double linked list which uses nodes with a generic data type.
I ran into a problem after testing the program for the first time. I got a NullPointerException error at the instance where I tried to add a new node to the head. After a little digging I found out that apparently Java doesn't remember that I set the successor of "head" to be "tail". I've already spent 20 minutes going over the code that sets the tail as head's successor but I just can't see what I did wrong.
Exception in thread "main" java.lang.NullPointerException
     at DLLNode.setNext(DLLNode.java:59)
     at DLLNode.<init>(DLLNode.java:17)
     at DLL.<init>(DLL.java:20)
     at Stack.<init>(Stack.java:11)
     at ParseTokens.<init>(ParseTokens.java:9)
     at Driver.main(Driver.java:16)The program is already too long to post here and broken up into multiple classes, so I will only post the important stuff. Note: Token is just a Record class that keeps two Strings, type and tagName for the xml tag to store.
DLLNode.java //node with generic datatype T
     private T data;
     private DLLNode<T> successor;
     private DLLNode<T> predecessor;
     public DLLNode(T d, DLLNode<T> next, DLLNode<T> prev) {
          this.setNodeData(d);
          this.setNext(next); //line 17
          this.setPrev(prev);
       public T getNodeData() {
            return this.data;
       public void setNodeData(T newData) {
            this.data = newData;
       public DLLNode<T> getNext() {
            return this.successor;
       public void setNext(DLLNode<T> newNext) {
            this.successor = newNext;
            System.out.println(newNext.toString()); //zeroed in on the problem being here; throws NullPointerException; line 59
       public DLLNode<T> getPrev() {
            return this.predecessor;
       public void setPrev(DLLNode<T> newPrev) {
            this.predecessor = newPrev;
       }DLL.java //manages the DLLNode objects
     private DLLNode<T> head;
     private DLLNode<T> tail;
//other vars
     public DLL() {
          this.setHead(new DLLNode<T>(null, tail, null)); //problem is probably here; after this, java doesn't see tail as head's successor; //line 20
          this.setTail(new DLLNode<T>(null, null, head));
          this.setSize(0);
       public void setHead(DLLNode<T> value) {
            this.head = value;
       public void setTail(DLLNode<T> value) {
            this.tail = value;
     public boolean addAtHead(T dllData) {
          DLLNode<T> newNode = new DLLNode<T>(dllData, this.head.getNext(), this.head);          
          this.getHead().getNext().setPrev(newNode); //original NullPointerException thrown here at the first instance of this method being used
          this.getHead().setNext(newNode);
          this.setSize(this.getSize() + 1);
          return ((newNode != null) && (newNode.getNext() != null) &&
                    (newNode.getPrev() != null));
     }Stack.java //manages a DLL object as a stack
     private DLL<T> dll;
     public Stack() {
          dll = new DLL<T>(); //line 11
          this.setSize(dll.getSize());
       public void push(T data) {
            dll.addAtHead(data); //original NullPointerException at first instance of push() being used
       }ParseTokens.java //class to actually go through the xml and list what it finds
     private Stack<Token> stack;
     public ParseTokens() {
          stack = new Stack<Token>(); //original error; line 9
     }Driver.java //main
ParseTokens parse = new ParseTokens();//line 16Thank you for any help.
Edited by: WhoCares357 on Feb 16, 2010 5:10 PM
Edited by: WhoCares357 on Feb 16, 2010 5:17 PM

A user on another forum h(http://preview.tinyurl.com/yjqx4a9) helped me find the problem. I had to create the head and tail first and then point them at each other. Thanks for all the help here.
@flounder Even though I've already solved my problem I am still confused by what you're saying. The double linked list I created has two placeholders so that I don't have to worry about how many nodes are included. To connect my new node I start at the head and point at whatever is connected to the head (whether it is the tail or another node) to set the successor and predecessor for the new node. I then break the old connections (from the head to the old node after it) and connect them to the new node. I don't see a problem in this, but I am most likely not understanding your concern.
I don't really want to let this go, because there might be a problem in my code that I don't see right now.
@AndrewThompson64 I'll use that the next time I have a problem. Thanks.

Similar Messages

  • Java doesn't recognize VectorList methods

    I get the following error trying to use Vector methods.
    ----jGRASP exec: javac -g /home/eugene/javafiles/book.java
    book.java:20: cannot find symbol
    symbol  : method elementAt(int)
    location: interface java.util.List<java.lang.String>
                   temp += author.elementAt( i ) + " ";
                                 ^
    1 error
    ----jGRASP wedge: exit code for process is 1.
    ----jGRASP: operation complete.
    import java.util.*;
    public class book
         private String title = "";
    //     String author[] = new String[ 4 ];
    /* Make author private */
         List<String> author = new Vector<String>();
         String publisher = "";
         int isbn = 0;
         double price = 0;
         int stock = 0;
    /*  ---------------------------------------- HERE IS THE PROBLEM CODE --------------------------------------- */     
         String showAuthor()
              String temp = "";
              int i;
              for (i = 0; i < author.size(); i++)
                   temp += author.elementAt( i ) + " ";
              return temp;     
         String showTitle()
              return title;
         void changeTitle( String input )
              title = input;
         String showPublisher()
              return publisher;
         void changePublisher( String input )
              publisher = input;
         int showIsbn()
              return isbn;
         void changeIsbn( int input )
              isbn = input;
         double showPrice()
              return price;
         void changePrice( double input )
              price = input;
         int showStock()
              return stock;
         void changeStock( int input )
              stock = input;
         book( String title, String publisher, int isbn, double price, int stock, String ... author )
              if ( author.length > 4 )
                   throw new IllegalArgumentException( "You have too many authors" );
    //          else if ( author.length == 0 )
    //               throw new IllegalArgumentException( "You have no authors" );
              this.title = title;
              this.publisher = publisher;
              this.isbn = isbn;
              this.price = price;
              this.stock = stock;
              this.author = new ArrayList<String>( Arrays.asList( author ) );
         public static void main( String[] args )
              book test = new book( "title", "publisher", 123, 12.20, 4, "eugene", "vadim" );
              System.out.println( test.title );
    }

    yougene wrote:
         List<String> author = new Vector<String>();
    Since you explicitly defined your reference to be of type List<String> you can only call methods that List has. And elementAt(int) is a method that's not existing in the List interface.
    Use .get(int) instead.

  • Java doesn't recognize jasperReport classes

    Hi guys could you please help me with my program it doesn't work so you guys might rectify the problem. Here is my code and errors:
    package helloWorld;
    import java.io.*;
    import java.sql.*;
    import javax.swing.*;
    import java.util.*;
    import net.sf.jasperreport.engine.JasperCompileManager;
    import net.sf.jasperreport.engine.JasperFillManager;
    import net.sf.jasperreport.engine.JasperPrintManager;
    import net.sf.jasperreport.engine.JasperExportManager;
    import net.sf.jasperreport.view.JasperDesignViewer;
    class jasperExample
    public static void main(String[] args)
    System.out.println("Hello World! for Jasper Example");
    try
    JasperDesign jasperDesign = JasperManager.loadXmlDesign(samke.xml);
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    Connection con1 = DriverManager.getConnection("com.mysql.jdbc.Driver","root","");
    Statement s1 = con1.createStatement();
    java.util.Map parameters = new java.util.HashMap();
    parameters.put("Tittle","Test JasperReport");
    JasperPrint report = JasperFillManager.fillReport(jasperReport, parameters, con1);
    JasperExportManager.exportReportToPdfFile(report,"report1.pdf");
    JasperViewer.viewReport(report);
    catch(Exception ex)
    System.out.print("Error!");
    These are the errors
    C:\Unify\NXJ\j2sdk\bin>javac sbo.java
    sbo.java:6: package net.sf.jasperreport.engine does not exist
    import net.sf.jasperreport.engine.JasperCompileManager;
    ^
    sbo.java:7: package net.sf.jasperreport.engine does not exist
    import net.sf.jasperreport.engine.JasperFillManager;
    ^
    sbo.java:8: package net.sf.jasperreport.engine does not exist
    import net.sf.jasperreport.engine.JasperPrintManager;
    ^
    sbo.java:9: package net.sf.jasperreport.engine does not exist
    import net.sf.jasperreport.engine.JasperExportManager;
    ^
    sbo.java:10: package net.sf.jasperreport.view does not exist
    import net.sf.jasperreport.view.JasperDesignViewer;
    ^
    sbo.java:19: cannot resolve symbol
    symbol : class JasperDesign
    location: class helloWorld.jasperExample
    JasperDesign jasperDesign = JasperManager.loadXmlDesign(samke.xml);
    ^
    sbo.java:19: cannot resolve symbol
    symbol : variable samke
    location: class helloWorld.jasperExample
    JasperDesign jasperDesign = JasperManager.loadXmlDesign(samke.xml);
    ^
    sbo.java:19: cannot resolve symbol
    symbol : variable JasperManager
    location: class helloWorld.jasperExample
    JasperDesign jasperDesign = JasperManager.loadXmlDesign(samke.xml);
    ^
    sbo.java:20: cannot resolve symbol
    symbol : class JasperReport
    location: class helloWorld.jasperExample
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    ^
    sbo.java:20: cannot resolve symbol
    symbol : variable JasperCompileManager
    location: class helloWorld.jasperExample
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    ^
    sbo.java:26: cannot resolve symbol
    symbol : class JasperPrint
    location: class helloWorld.jasperExample
    JasperPrint report = JasperFillManager.fillReport(jasperReport, parameters, c
    on1);
    ^
    sbo.java:26: cannot resolve symbol
    symbol : variable JasperFillManager
    location: class helloWorld.jasperExample
    JasperPrint report = JasperFillManager.fillReport(jasperReport, parameters, c
    on1);
    ^
    sbo.java:27: cannot resolve symbol
    symbol : variable JasperExportManager
    location: class helloWorld.jasperExample
    JasperExportManager.exportReportToPdfFile(report,"report1.pdf");
    ^
    sbo.java:28: cannot resolve symbol
    symbol : variable JasperViewer
    location: class helloWorld.jasperExample
    JasperViewer.viewReport(report);
    ^
    14 errors
    Help me guys I am burning

    1. right click ur "my computer" icon.
    2. then properties -> advanced -> Enviroment variable
    3. user variable - > add
    4. add two variavle
    i.
    Name : JAVA_HOME
    Value : jdk home
    ii
    Name : PATH
    Value : .; jdk bin path ; tomcat path

  • RegisterOutParam doesn't recognize types that are defined between quotes.

    Suppose one defines a type as below:
    create or replace type "VectorOfInt" as varray(300) of number(10);
    in the C++ program, when using statement -> registerOutParam (...), the fourth argument is the type.
    If one passes ... registerOutParam(..., "MYSCHEMA.\"VectorOfInt\""), that is, escaping the type name between double quotes, to indicate that the case should be respected, doesn't work. Everywhere else this construct seems to work fine.
    If, however, one defines:
    create or replace type VectorOfInt as varray(300) of number(10);
    and one passes... registerOutParam (...,"MYSCHEMA.VECTOROFINT"), that works fine.
    Is that a bug... or am I misunderstanding the concepts?

    Shaun,
    Don't know if this is the problem or not, but I had the same thing happen and my problem was that I had signed in to one device with my @mac.com address and the other device with my @me.com address. Both were recognized by Apple &amp; I never got any errors (I only have one Apple ID account), but my data would never sync. Once I signed in with the same addy on both, it worked fine.

  • App store doesn't recognize installed software

    Ok. I've upgraded to Lion. The app store STILL doesn't recognize software that's on the Mac, and this INCLUDES Apple apps. The only software that shows up as installed is Lion.

    no it gets this error when I try to update:
    why?? it has no sense at all! I'm an apple user for 10 years now; I loved apple for not doing this kind of windowsish errors!

  • Mail doesn't recognize contacts from my address book

    After installing snow leopard it seems that the Mail application doesn't recognize names that are in my address book. For instance when I start a new email, I will start typing a name in the "to" field, where it used to guess the contacts name it no longer does this. I have about 1800 names in my address book, do I have to introduce these to the mail application one by one in order for it to recognize them?
    Thanks for any help you can give.

    To be more clear (in hopes you can get it to work!) :
    Under Mail -> Preferences -> Composing
    1. Be sure to CHECK the box that says autocomplete addresses under the Addressing heading.
    2. Quit Mail and restart.
    If that doesn't work then I would suggest quitting Mail and trashing the Preference file (~/Library/Preferences/com.apple.mail.plist). Then restart Mail and make sure the box is checked as above and restart Mail. Note that all preferences will be reset to the default and you may need to reconfigure Mail the way you like it. You can always drag the plist file back and restart Mail.app to restore your previous settings.
    Ed

  • HT1338 I download Adobe Flash but it doesn't install. Each time I encounter something that needs Adobe Flash it tells me I don't have it. I am getting tired downloading it and then it isn't there.

    I download Adobe Flash but it doesn't install. Each time I encounter something that needs Adobe Flash it tells me I don't have it. I am getting tired downloading it and then it isn't there.

    install_flash_player_10_osx.dmg
    install_flash_player_10_osx-1.dmg
    install_flash_player_10_osx-2.dmg
    install_flash_player_10_osx-3.dmg
    install_flash_player_10_osx-4.dmg
    etc to -9
    Those are the ones you downloaded. Ten times, apparently. Since install_flash_player_10_osx.dmg already existed, the next download was appended with -1. The next -2, etc. They'll all be identical, so it doesn't matter which one you use. Though I'd go with the last one as it may be a slightly updated version from the first download, depending on how long ago you did the first one.
    A .dmg file is a Disk Image. When you double click them, they open up a pseudo drive on the desktop. When you open one of these ten items, the Flash installer will appear in a file window. Run it to install Flash. Then close the file window (displaying from the psuedo drive) and then put the "drive" in the trash to dismount it. You can then delete all of those.
    Looks like you also downloaded the Adobe Reader twice. Versions 10.1.2 and 10.1.3. Also Skype, whatever the Thomson thing is, and an unnecessary Flash uninstaller (the Flash installer will put an uninstaller in the Utilities folder).

  • My apple ID and password, recognized through out the Cloud, is not being recognized in the itunes store. I am signed into itunes.When I want to change something in my account, the sign in prompt comes up and doesn't recognize my PW

    My apple ID and password, recognized through out the Cloud, is not being recognized in the itunes store. I am signed into itunes.When I want to change something in my account, the sign in prompt comes up and doesn't recognize my PW

    Solved the problem. I had to allow cookies for safari and it run - as here: Re: itunes keeps asking for my apple id password. it's NOT entered incorrectly.

  • After i plug in my iphone 5s, it always asks me to trust the laptop, i click trust and my laptop makes that noise as if I've pulled my phone out, but i haven't, so now my itunes doesn't recognize my phone, please please help me?

    After i plug in my iphone 5s, it always asks me to trust the laptop, i click trust and my laptop makes that noise as if I've pulled my phone out, but i haven't, so now my itunes doesn't recognize my phone, please please help me?
    THis also happened with my old iphone 4s
    I need help!

    Hi loist,
    Thanks for visiting Apple Support Communities.
    If your iPhone is not being recognized by your computer after you click "Trust," the troubleshooting steps found here can help:
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    Cheers,
    Jeremy

  • I just downloaded AOL Desktop 1.7 for Mac and I can't get my email to work. It welcomes me but I know I have new email but it doesn't recognize that I have ANY mail at all. HELPPPPPPPP Please

    i just downloaded AOL Desktop 1.7 for Mac and I can't get my email to work. It welcomes me but I know I have new email but it doesn't recognize that I have ANY mail at all. HELPPPPPPPP Please

    Hey I've been all over and can't get any help. I'm well aware its not an Apple product but its an app for Mac OS so I thought I'd try here. I bought 2 new iMacs yesterday for my parents (5K) and I'm just trying to get them some help as there in their 70's and AOL is all they know.
    But hey thanks for your help,

  • I am trying to sync an old ipod nano (2nd generation) to my itunes on a windows pc but the itunes doesn't recognize the nano and says that it is synced with another computer. Unfortunately, I don't have the old computer now. How do I sync this nano to itu

    I am trying to sync an old ipod nano (2nd generation) to my itunes on a windows pc but the itunes doesn't recognize the nano and says that it is synced with another  computer. Unfortunately, I don't have the old computer now. How do I sync this nano to itunes ?

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • Hi, my name's Michael and I had a question about my iPod touch. I recently dropped it but I still have a warranty and Apple Support said they couldn't fix that my screen doesn't recognize my finger is on there trying to do anything?

    Hi, my iPod touch was recently dropped but afterwards I called Apple Support and they told me I have a 17 day warranty for my Apple iPod Touch, so then I asked them if I could send it in to get fixed but what had happened to my iPod was that when I click the home button and try to ''Slide to Unlock" it doesn't recognize that I'm trying to do anything else the only thing that I can do is press the "Sleep" and "Home" Buttons and nothing else. Anything you can do to help me please??

    Even if you were still under AppleCare warranty, it would not cover damage from a fall.
    That "17 day" warranty makes no sense, though. iPods have a 1-year free AppleCare warranty for service, and 90 days for free phone support:
    http://www.apple.com/support/products/ipod.html
    Apple can repair just about anything that might be wrong with your iPod, but it will cost you. Call, explain the problem, ask for a repair appointment at your nearest Apple Store (or get a case number and ask for instructions to mail it in for a repair), but get a firm quote on the repair cost before authorizing the repair (or mailing it in for repair).
    800-APL-CARE (800-275-2273)

  • I upgraded my iTunes to 10.7 on my MacBook Pro - after that iTunes doesn't recognize my iPhone 4S 6.0.1 (10A523) in the iTunes sidebar. Solutions?

    I upgraded my iTunes to 10.7 on my MacBook Pro - after that iTunes doesn't recognize my iPhone 4S 6.0.1 (10A523) in the iTunes sidebar. Solutions?
    (Both upgrades to the phone and lap-top were done based on Apples suggestion, so I find it strange it doesn't work automatically, which should be a basic reason for choosing Apples costly products!)

    Try rebooting your computer.
    You might also try downloading and installing iTunes 11 which came out today.

  • I upgraded my iTunes to 10.7, after that iTunes doesn't recognize my iPhone 4S 6.0.1 (10A523) in the iTunes sidebar. Solutions?

    I upgraded my iTunes to 10.7, after that iTunes doesn't recognize my iPhone 4S 6.0.1 (10A523) in the iTunes sidebar. Solutions?

    You've posted in the iTunes Match forum. You'll probably get better help posting in the Using iPhone forum. Or the appropriate iTunes forum.

  • Quick Time Doesn't recognize most of my emails that have attachments

    When I get an Email with a video attachment, Quick Time will not play it. It says that Quick Time doesn't recognize the format. Until I updated quick time, Windows media player was my default player. How can I switch back to making windows media my default player again?

    http://wiki.answers.com/Q/Howdo_you_make_windows_media_player_your_default_mediaplayer
    among many other answers easily found with a quick web search.
    Regards.

Maybe you are looking for