Invalid method declaration; return type required

It is telling me that a return type is required for the constructor. I looked it up in the 5th edition of Android Programming Big Nerd Ranch and saw that it was the same. I don’t know why it’s highlighting the private and constructor keywords.

None of the errors show up when I make the project, yet it is highlighting the keywords like there is an error.


package com.bignerdranch.android.criminalintent;


import android.content.Context;

class CrimeRepository private constructor(context: Context){
    
    companion object {
        private var INSTANCE: CrimeRepository? = null

            fun initialize(context: Context) {
            if (Instance == null) {
                INSTANCE = CrimeRepository(context)

            }
        }
        fun get(): CrimeRepository {
            return INSTANCE ?:
    throw IllegalStateException("CrimeRepository must be initialized")
        }
    }
}

Ok, I found the error myself(unless I have invisible elves helping me). For future reference for any other newbs like me. Be sure that the file you make is a Kotlin class. It is easy at least to me, to mix up the two when it brings up the prompt to choose the file type in Android Studio. I had it as a Java class and that is why there were errors showing up. To figure this out, I used my critical thinking skills, and I think others should do the same. If there is a situation where the code is obviously right, there is probably a simple explanation for the error. I hope this helps others like me in similar situations.