Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

Android Studio assert not working

I'm calling findViewById and Android Studio (version 3.1, stable) prompts me to put an assertion:

enter image description here

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:

enter image description here

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?

Upvotes: 2

Views: 1930

Answers (1)

Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

Apparently, (as stated in the comments) assertions are disabled by default but encouraged by Android Studio.

In this manner, the "problem" can be classified as a misleading UX issue rather than a technical problem.

Upvotes: 3

Related Questions