Posts with the tag kotlin:

Mysterious Kotlin 'parameter non-null exception'

| 1 minute read | kotlin
This week I found myself confused by an exception when writing a simple extension method on Android’s TextView. Consider the following extension method: fun TextView.doSomething() { } This is about as simple as it could get - it has no parameters and returns nothing. However, when I tried to use it, I found myself with the following exception: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter $receiver But that’s weird - it looks like there’s a parameter called $receiver which is null… Except, I don’t have a parameter at all!

Creating a Custom Type Adapter for Moshi

| 3 minute read | kotlin moshi
In building an app which guides a user through a process, stage by stage, we would probably use an enum to represent it. For example, consider a process which goes from NOT_STARTED, through IN_PROGRESS to one of either REJECTED or COMPLETED: The logic for moving between these stages is transparent to the app, we show different screens based on which stage a user is in. But what if the mapping of stages isn’t 1:1 on the client and the server?