I'm calling findViewById and Android Studio (version 3.1, stable) prompts me to put an assertion:
When I select it, it adds the following line above the selected line:
assert v != null;
Great. I run the app, and the View v is null. However, assertion doesn't work and it jumps to the line below it in debugger:
How is this even possible? It was Android Studio's own suggestion, and I didn't change a thing. Its own recommendation/autogenerated code is not working. Am I missing something obvious?


assert(and here is a good discussion about some reasons why). Instead I prefer explicit (not disableable) validators such as Guava Preconditions (might not be available in Android).if (v == null && BuildConfig.DEBUG) Log.e("your_tag", "your_message"); else { mapView = v.findViewById (R.id.MapView);}if(root !=null) mapView = root.findViewById(R.id.MapView);findViewByIdat all. It reduces boilerplate and runtime code. So if your project is decently sized, you can maybe look at Butterknife.