I am having a problem with the following lines where car
is a String
array which has not been initialized/has no elements.
String c
Well, in this case the car
variable will be null
, so dereferencing it (as you do when you access car.length
) will throw a NullPointerException
.
In fact, you can't access that variable at all until some value has definitely been assigned to it - otherwise the compiler will complain that "variable car might not have been initialized".
What is it you're trying to do here (it's not clear to me exactly what "solution" you're looking for)?
I think you are looking for this
String[] car = new String[10];
int size = car.length;