3 Replies Latest reply: May 16, 2008 2:44 PM by 807601 RSS

    Re: Getting data from an abstract superclass

    807601
      all this code and you don't even show the complete class where the error occurs

      anyway, a NullPointerException only occurs on that line if "dvds" is null or "dvds[0]" is null. Why don't you print them out before to see:
      System.out.println(dvds);
      System.out.println(dvds[0]);
      why do you increment two different ways here:
      Kaeota wrote:
      I then add it to an array:
           public static void addToArray( dvd dvdToAdd )
      //...
                     dvds[++dvdCount] = dvdToAdd;
      //...
                     temp[dvdCount++] = dvdToAdd;
           
        • 1. Re: Getting data from an abstract superclass
          807601
          I didn't put the entire class in because i didn't see the need, sorry if i was mistaken.

          I had no clue your could do that with println, and you're right, dvds[0] is null, which means there's something wrong with how i add it to my array.

          The different incriments were because halfway through this code i learnt that in future i will be more likely to use ++varName than varName++, thanks for pointing it out tho, i thought i'd got them all.
          • 2. Re: Getting data from an abstract superclass
            795426
            Kaeota wrote:
            The different incriments were because halfway through this code i learnt that in future i will be more likely to use ++varName than varName++, thanks for pointing it out tho, i thought i'd got them all.
            FYI: micro-optimizations like that are really pointless.
            • 3. Re: Getting data from an abstract superclass
              807601
              Oh I know. Though i didn't do it so much as an optimization as to stop myself from getting into a habit I'm going to need to break later.

              Kinda funny in this case, because the reason for the null pointer exception was because the first peice of data went to the second element, rather than the first, of the array.

              Thanks though =D