Thursday, 15 May 2014

java - Adding to custom linked list causes NullPointerException -


Therefore, adding stuff to my custom linked list NullPointerException , And I can not understand why, for my life, the program aims to emulate a chest of a drawer, in which there is a list in which the drawers are nodes. Each of the drawers has a list in which the domestic items are included in the form of nodes.

There are relevant bits of code here error occurs when I have a: new chestoff drivers (3); In my UI category:

  Public class chestoff drivers {Private Stable Onyelist Chest; Private static int [] parametres; Public Chest Of Driers (Intro Drawers) {chest = new OwnList (); Surge (); } To make public static void () (for (int i = 0; i & lt; parametres.length; i ++) {Object drawer = New drawer (i, paramometers [i]); Chest.add (i, drawer ); // This is causing the error}}}   

class is referred to here for the square of the drawer int. I requires drawer capability in the form of ID and int parametres before the list is made in the parametres [] array is filled and it contains the drawer's capacity Information for The included list in question ( OwnList) is 100% working correctly because it is part of a given curriculum content, it is similar to Java itself. I have another test Tested the class in class and it worked fine, I made a mistake here, please help!

< P> The problem is that you are not starting the parametres array, this field is empty by default Aagi you're either will be initiated where it is proclaimed, or addition to a stable starting block, why are two fields and construction method static? They are definitely looking like an example state ...

This is a better version:

  Public Ultimate Division Chestoff Drawers {Private Finals O'Neilist Chest = New Onlist (); Private Final Ent Parameters; Public Chest Of Drawers (Intra Drawers) {If (Dare & Lt; 0) Exclude New Invalid Argument Exceptions ("Drafts can not be negative"); Chest = new onilist (); Parametres = new int [drawer]; // & lt; - I believe that it means the initial (); } Private Zero Start () (for (int i = 0; i & lt; parametres.length; i ++) {Object Drawer = New Drawer (I, Parameters [i]); //   

I'm not sure that you really need parameters array to include (a new array of int Zero values ​​will be filled) - But I'll leave it as one exercise the reader: -)

No comments:

Post a Comment