Столкнулся с проблемой, при переходе в окно с картой приложение иногда крашится с ошибкой
java.lang.AssertionError: setApiKey() should be called before initialize()!
Код MainActivity.kt:
package com.example.myapplication
// Здесь импорты //
class MainActivity : AppCompatActivity(), UserLocationObjectListener, Session.SearchListener, CameraListener {
private lateinit var mapView: MapView
private lateinit var probkibut:Button
private lateinit var locationMapKit: UserLocationLayer
private lateinit var searchEdit: EditText
private lateinit var searchManager: SearchManager
private lateinit var searchSession: Session
private lateinit var egk:Button
private lateinit var myloc:Button
private lateinit var qwe:Button
private var loc = false
private fun sumbitQuery(query: String){
searchSession = searchManager.submit(query, VisibleRegionUtils.toPolygon(mapView.map.visibleRegion), SearchOptions(), this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MapKitFactory.setApiKey("myAPI")
MapKitFactory.initialize(this)
setContentView(R.layout.activity_main)
mapView = findViewById(R.id.mapview)
mapView.map.move(CameraPosition(Point(55.383297, 39.035919), 17.0f, 150.0f, 30.0f),
Animation(Animation.Type.SMOOTH, 5f), null)
var mapkit:MapKit = MapKitFactory.getInstance()
requstLocationPermission()
qwe = findViewById(R.id.qwe)
qwe.setOnClickListener{
val intent = Intent(this@MainActivity, act2::class.java)
startActivity(intent)
}
// дальше код //
Код act2:
package com.example.myapplication
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class act2 : AppCompatActivity() {
private lateinit var nback:Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_act2)
nback = findViewById(R.id.nback)
nback.setOnClickListener {
val intent = Intent(this@act2, MainActivity::class.java)
val handler = android.os.Handler()
handler.postDelayed({ startActivity(intent) }, 1500)
}
}
}
Помогите пожалуйста