when I try to define an spinner, this Run time exception is thrown. Why?
Asked
Active
Viewed 3,088 times
-4

Narendra Singh
- 3,990
- 5
- 37
- 78

DanialAbdi
- 183
- 1
- 4
- 17
-
oh,you cannot do this like instance a object at out of onCreate. you need to instance object at onCreate Method – birds May 27 '15 at 04:41
-
You should call findViewById(int) after you call setcontentview(layout resId); Move the code after setContentView will work – Vishnu Prabhu May 27 '15 at 04:41
-
Move pointed line after setContentView in onCreate method – ρяσѕρєя K May 27 '15 at 04:41
-
**Never** post images of your code or the logcat, copy and paste it there instead! – Xaver Kapeller May 27 '15 at 04:44
1 Answers
3
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

Stefano Vuerich
- 996
- 1
- 7
- 28