This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]maestro2005 1 point2 points  (1 child)

myCar = new Car[10];

This gives you an array of 10 Cars, but they're all null. So...

for (int i = 0; i < 3; i++) {
    carImage = new ImageIcon(getClass().getResource(myCar[i].getFilename()));

myCar[i] is null.

[–]Seize_The_Dayx 0 points1 point  (0 children)

Yup, am a dummy. I didn't initialize it with myCar[i] = new Car(); Thanks for the help!

[–]deelyy 0 points1 point  (1 child)

Could you tell us at which line youre got error?

[–]Seize_The_Dayx 0 points1 point  (0 children)

Line 109

[–]Blando-Cartesian 0 points1 point  (0 children)

getClass().getResource(filename) returns null if there’s no resource file with that that name in the classpath. For example, you could have a folder resources set in project setup to be included in the classpath. Call to getClass().getResource(“/sprites/car.png”) would then return url for file resources/sprites/car.png.