#How do I create an array of objects? Cannot store to object array because b is null. Thanks

1 messages · Page 1 of 1 (latest)

river gulch
#
public class BicycleInventory
{
    private static Bicycle [] b;
    
    public BicycleInventory()
    {
        b = new Bicycle[25];
    }
    
    public static void readInventory()
    {
        int index = 0;                    
        try                
        {                        
            File f = new File("bicycle.txt");      
            Scanner file = new Scanner(f);        
            while (file.hasNextLine())
            {                
            String[] line = file.nextLine().split(",");
            String type = line[0];                            int wheelSize = Integer.parseInt(line[1]);
            boolean assembled = Boolean.parseBoolean(line[2]);    
            char gender = line[3].charAt(0);    
            b[index] = new Bicycle(type, wheelSize, assembled, gender);
            index++;
                }////catch...blahblahblah
fossil brookBOT
#

Hey, @river gulch!
Please remember to /close this post once your question has been answered!

hushed flame
#

i have the same problem lol

north dew
#
    private static Bicycle [] b = new Bicycle[25];
#

OR make readInventory() NOT static

river gulch
#

thanks!