why this runtime is occured :Unable to instantiate

2019-09-22 05:18发布

问题:

when I try to define an spinner, this Run time exception is thrown. Why?

回答1:

You have to initialize your spinner in the onCreate method, so move

CARS_TYPE = (Spinner)findViewById(...);

inside onCreate() after setContentView

one more thing, CARS_TYPE should not be a constant, better if you call it carsType instead