'Expecting a top level declaration' when creating a Kotlin Class

Issue

I am getting this error Expecting a top level declaration on this very simple class declaration

public class NetworkConnectionInterceptor implements Interceptor{

}

I have done invalidate cache several times but the error still exists, any ideas please?

enter image description here

Solution

Pay attention to the file type, its .kt, meaning its Kotlin.

What your’e attempting here is Java

public class NetworkConnectionInterceptor implements Interceptor{

}

So please do it this way if you want a Kotlin class,

class NetworkConnectionInterceptor : Interceptor {

}

But if you really want this as Java, you then have to create a new file as Java

Answered By – z.g.y

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published