Активити c MapKit вылетает (Java Android)
Хочу подключить Яндекс.Карты (MapKit) в приложении. При запуске активити с картой приложение вылетает. Код активити:
package com.example.mobnetworkapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.yandex.mapkit.Animation;
import com.yandex.mapkit.MapKitFactory;
import com.yandex.mapkit.geometry.Point;
import com.yandex.mapkit.map.CameraPosition;
import com.yandex.mapkit.mapview.MapView;
public class MapEvents extends AppCompatActivity {
private final Point TARGET_LOCATION = new Point(59.945933, 30.320045);
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_events);
String MAPKIT_API_KEY = "мой ключ";
MapKitFactory.setApiKey(MAPKIT_API_KEY);
MapKitFactory.initialize(this);
setContentView(R.layout.map_events);
mapView = (MapView) findViewById(R.id.mapview);
mapView.getMap().move(
new CameraPosition(TARGET_LOCATION, 11.0f, 0.0f, 0.0f),
new Animation(Animation.Type.SMOOTH, 0),
null);
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
MapKitFactory.getInstance().onStop();
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
MapKitFactory.getInstance().onStart();
}
}
Код макета:
<?xml version="1.0" encoding="utf-8"?>
<com.yandex.mapkit.mapview.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.yandex.mapkit.mapview.MapView>
Содержание ошибки:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ovapp/com.example.mobnetworkapp.MapEvents}: android.view.InflateException: Binary XML file line #2 in com.example.ovapp:layout/map_events: Binary XML file line #2 in com.example.ovapp:layout/map_events: Error inflating class com.yandex.mapkit.mapview.MapView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3895)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8347)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.ovapp:layout/map_events: Binary XML file line #2 in com.example.ovapp:layout/map_events: Error inflating class com.yandex.mapkit.mapview.MapView
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.ovapp:layout/map_events: Error inflating class com.yandex.mapkit.mapview.MapView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:864)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1016)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
at android.view.LayoutInflater.inflate(LayoutInflater.java:669)
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.mobnetworkapp.MapEvents.onCreate(MapEvents.java:19)
at android.app.Activity.performCreate(Activity.java:8085)
at android.app.Activity.performCreate(Activity.java:8073)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3868)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8347)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.RuntimeException: Required method parameter "key" cannot be null
Exception stack trace (top 20 entries):
# 0: 2282988 /data/app/com.example.ovapp-il0DVZcB2pTjOXTO7cN6Fg==/lib/arm64/libcom.yandex.runtime.so _ZN6yandex4maps7runtime9backtrace9BacktraceC2Ev
# 1: 2307164 /data/app/com.example.ovapp-il0DVZcB2pTjOXTO7cN6Fg==/lib/arm64/libcom.yandex.runtime.so
E/AndroidRuntime: # 2: 2306600 /data/app/com.example.ovapp-il0DVZcB2pTjOXTO7cN6Fg==/lib/arm64/libcom.yandex.runtime.so _ZN6yandex4maps7runtime9ExceptionC2ERKNSt6__ndk112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS2_8SeverityE
# 3: 3004084 /data/app/com.example.ovapp-il0DVZcB2pTjOXTO7cN6Fg==/lib/arm64/libcom.yandex.mapkit.so
# 4: 7831536 /data/app/com.example.ovapp-il0DVZcB2pTjOXTO7cN6Fg==/lib/arm64/libcom.yandex.mapkit.so Java_com_yandex_mapkit_internal_MapKitBinding_setApiKey__Ljava_lang_String_2
# 5: 1360724 /apex/com.android.runtime/lib64/libart.so
# 6: 1323832 /apex/com.android.runtime/lib64/libart.so
# 7: 1384872 /apex/com.android.runtime/lib64/libart.so _ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc
# 8: 3072868 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_11ShadowFrameEtPNS_6JValueE
# 9: 3053108 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE
#10: 3112912 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter20ExecuteSwitchImplCppILb0ELb0EEEvPNS0_17SwitchImplContextE
#11: 1371100 /apex/com.android.runtime/lib64/libart.so
#12: 2879644 /apex/com.android.runtime/lib64/libart.so
#13: 2903436 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadERKNS_20CodeItemDataAccessorEPNS_11ShadowFrameEPNS_6JValueE
#14: 3053080 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE
#15: 3107752 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter20ExecuteSwitchImplCppILb0ELb0EEEvPNS0_17SwitchImplContextE
#16: 1371100 /apex/com.android.runtime/lib64/libart.so
#17: 2879644 /apex/com.android.runtime/lib64/libart.so
#18: 2903436 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadERKNS_20CodeItemDataAccessorEPNS_11ShadowFrameEPNS_6JValueE
#19: 3053080 /apex/com.android.runtime/lib64/libart.so _ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE
at com.yandex.mapkit.internal.MapKitBinding.setApiKey(Native Method)
at com.yandex.mapkit.MapKitFactory.initialize(MapKitFactory.java:27)
at com.yandex.mapkit.mapview.MapView.<init>(MapView.java:51)
at com.yandex.mapkit.mapview.MapView.<init>(MapView.java:44)
... 26 more
Ключ получен в кабинете разработчика и активен. Библиотеки, зависимости и прочее подключено в соответствии с инструкцией. Поиск по ошибке не дал результатов, всё не то. Подскажите, в чём может быть проблема в моём случае.