I'm stuck with a problem in my Android Studio project. I want to implement google maps but always get the Binary XML file line #10 error.
Logcat:
2022-08-23 21:25:23.421 13344-13344/com.package.name E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.name, PID: 13344
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.name/com.package.name.Game}: android.view.InflateException: Binary XML file line #10 in com.package.name:layout/activity_game: Binary XML file line #10 in com.package.name:layout/activity_game: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3686)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7892)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: android.view.InflateException: Binary XML file line #10 in com.package.name:layout/activity_game: Binary XML file line #10 in com.package.name:layout/activity_game: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #10 in com.package.name:layout/activity_game: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.drd.p.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):6)
at com.google.maps.api.android.lib6.auth.f.i(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):1)
at com.google.maps.api.android.lib6.impl.l.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):24)
at com.google.android.gms.maps.internal.CreatorImpl.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):7)
at com.google.android.gms.maps.internal.CreatorImpl.logInitialization(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):3)
at com.google.android.gms.maps.internal.g.aY(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):5)
at ej.onTransact(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (190800-0):4)
at android.os.Binder.transact(Binder.java:1164)
at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.1.0:2)
at com.google.android.gms.maps.internal.zze.zzl(com.google.android.gms:play-services-maps@@18.1.0:4)
at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.1.0:12)
at com.google.android.gms.maps.MapsInitializer.initialize(com.google.android.gms:play-services-maps@@18.1.0:1)
at com.google.android.gms.maps.zzav.zzc(com.google.android.gms:play-services-maps@@18.1.0:2)
at com.google.android.gms.maps.zzav.createDelegate(com.google.android.gms:play-services-maps@@18.1.0:1)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.1.0:6)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(com.google.android.gms:play-services-base@@18.1.0:1)
at com.google.android.gms.maps.SupportMapFragment.onCreate(com.google.android.gms:play-services-maps@@18.1.0:5)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:3090)
2022-08-23 21:25:23.422 13344-13344/com.package.name E/AndroidRuntime: at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:475)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:257)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1890)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1814)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1720)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.kt:158)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:53)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:136)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:248)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:227)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.package.name.Game.onCreate(Game.kt:16)
at android.app.Activity.performCreate(Activity.java:8285)
at android.app.Activity.performCreate(Activity.java:8264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3667)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7892)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
XML-File:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Game">
<androidx.fragment.app.FragmentContainerView xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@ id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:uiZoomControls="true"
map:uiRotateGestures="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
Gradle Dependencies (In other posts a lot of people talked about them) dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-base:18.1.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation "androidx.fragment:fragment-ktx:1.5.2"
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
I tried all other solutions I found on StackOverflow, but none of them helped. Thanks in advance!
CodePudding user response:
Did you check this?
...
Caused by: java.lang.RuntimeException: API key not found.
Check that <meta-data android:name="com.google.android.geo.API_KEY"
android:value="your API key"/> is in the <application> element of AndroidManifest.xml
...
Detailed steps here