I use a EmptyActivity and want put a MapView in MainActivity, I think I need implements OnMapReadyCallback, This is my code.
package com.example.myapplication
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.OnMapReadyCallback
class MainActivity : AppCompatActivity(), OnMapReadyCallback{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Why I got this error: Class 'MainActivity' is not abstract and does not implement abstract member public abstract fun onMapReady(p0: GoogleMap!): Unit defined in com.google.android.gms.maps.OnMapReadyCallback.
OnMapReadyCallback
is an interface that has a single method onMapReady
. What the compiler is telling you is that when you implement an interface, if your class is itself not an interface nor abstract, you have to declare implementations for the methods defined in the interface. So you would update your activity like this:
class MainActivity : AppCompatActivity(), OnMapReadyCallback{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onMapReady(map: GoogleMap) {
// Add implementation here
}
}
This might solve this particular issue, but it sounds like you might have to read up on interfaces and how they work in Kotlin and in Java.
Hope that helps!