gpt4 book ai didi

android - 谷歌地图 fragment 无法膨胀

转载 作者:搜寻专家 更新时间:2023-11-01 09:00:05 25 4
gpt4 key购买 nike

我一直在向我的 Android 项目添加 map ,每当我的类加载带有 map fragment 的 XML 文件时它崩溃,我正在学习本教程

(https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key)

我使用的是 Nexus 7 (Jellybean 4.1),所以这应该不是问题,这是我的类(class):

package com.app.thetoolstore;

import android.app.Activity;
import android.os.Bundle;

public class Tool_map extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
}


}

这是我的 XML:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#001" >


<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>



</LinearLayout>

最后是我的堆栈跟踪:

04-04 10:01:35.551: E/AndroidRuntime(14362): FATAL EXCEPTION: main
04-04 10:01:35.551: E/AndroidRuntime(14362): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.thetoolstore/com.app.thetoolstore.Tool_map}: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.os.Looper.loop(Looper.java:150)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.main(ActivityThread.java:4385)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-04 10:01:35.551: E/AndroidRuntime(14362): at dalvik.system.NativeStart.main(Native Method)
04-04 10:01:35.551: E/AndroidRuntime(14362): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.Activity.setContentView(Activity.java:1742)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.app.thetoolstore.Tool_map.onCreate(Tool_map.java:11)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
04-04 10:01:35.551: E/AndroidRuntime(14362): ... 11 more
04-04 10:01:35.551: E/AndroidRuntime(14362): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.app.thetoolstore-2.apk]
04-04 10:01:35.551: E/AndroidRuntime(14362): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-04 10:01:35.551: E/AndroidRuntime(14362): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-04 10:01:35.551: E/AndroidRuntime(14362): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-04 10:01:35.551: E/AndroidRuntime(14362): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-04 10:01:35.551: E/AndroidRuntime(14362): ... 20 more

更新

我使用本教程解决了这个问题 https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw具体来说,我遇到了 libs 和 google-pay 服务的问题。

最佳答案

嗯,很多问题1)你需要使用FragmentActivity而不是Activity

2) android:name="com.google.android.gms.maps.MapFragment"替换为 android:name="com.google.android.gms.maps.SupportMapFragment"/>

3) 您需要在 list 文件中添加 key 并使用 Google Android Map API v2

4) 引用本教程http://www.vogella.com/articles/AndroidGoogleMaps/article.html

关于android - 谷歌地图 fragment 无法膨胀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15807559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com