The title is the name of Item 17 from the second edition of Joshua Bloch’s Effective Java. I did not see the importance of this advice – or should we call it rule – until I ran into an issue during Android development that was caused by violations of this rule in the Android Framework.
Tag: pitfall
This post will be about an interesting observation I made when working on a custom View that did not extend EditText
, but contained one.
One of the new features introduced in Java 7 was the possibility to handle multiple exception types in a single catch block.
Starting with March 2014 (added in SDK Tools 22.6), this feature can be used for Android applications too when targeting Android Froyo or later.
However, in Android, there is a special case where multi-catch can bring trouble for the developers.
I knew that I would write a post about this phenomenon as soon as I met it.
Here is the story: during my work, I was assigned to fix a bug. The bug was the following: when navigating to a certain screen, the application crashed with ClassCastException saying that I cannot cast Linearlayout to FrameLayout.
I checked the layout file that was inflated, and the root element was indeed FrameLayout, making the error seem impossible. But then… what was wrong?