gpt4 book ai didi

java - Google Maps API Android - 膨胀类 fragment 时出错

转载 作者:行者123 更新时间:2023-12-01 23:50:54 25 4
gpt4 key购买 nike

我知道 StackOverFlow 上有很多关于这个问题的主题,但是没有一个可以帮助我。我正在做一个非常基本的应用程序,我只想显示 map 。

  • 我已将 google-play-services_lib 导入到我的主项目中。
  • 我已生成 API key 。

这是我的 AndroidManifest.xml 文件:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.linkme2night"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />

<permission
android:name="com.linkme2night.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.linkme2night.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.linkme2night.view.interactwithvenue.InteractWithVenueActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.linkme2night.view.openvenuesmap.OpenVenuesMapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBJVHZJr1Q14fcvEHBkAUT1A_ZH4eQlnrI" />
</application>

</manifest>

这是我的布局 XML 文件:

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

这是我的代码:

public class OpenVenuesMapActivity extends FragmentActivity  {

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

我在 Sony XPeria J 上运行该应用程序。我收到 Loc Cat 生成的以下错误:

05-01 18:51:48.544: E/AndroidRuntime(10794): FATAL EXCEPTION: main
05-01 18:51:48.544: E/AndroidRuntime(10794): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.linkme2night/com.linkme2night.view.openvenuesmap.OpenVenuesMapActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2065)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2090)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread.access$600(ActivityThread.java:136)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.os.Looper.loop(Looper.java:137)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread.main(ActivityThread.java:4802)
05-01 18:51:48.544: E/AndroidRuntime(10794): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 18:51:48.544: E/AndroidRuntime(10794): at java.lang.reflect.Method.invoke(Method.java:511)
05-01 18:51:48.544: E/AndroidRuntime(10794): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
05-01 18:51:48.544: E/AndroidRuntime(10794): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
05-01 18:51:48.544: E/AndroidRuntime(10794): at dalvik.system.NativeStart.main(Native Method)
05-01 18:51:48.544: E/AndroidRuntime(10794): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-01 18:51:48.544: E/AndroidRuntime(10794): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.Activity.setContentView(Activity.java:1869)
05-01 18:51:48.544: E/AndroidRuntime(10794): at com.linkme2night.view.openvenuesmap.OpenVenuesMapActivity.onCreate(OpenVenuesMapActivity.java:14)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.Activity.performCreate(Activity.java:5013)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029)
05-01 18:51:48.544: E/AndroidRuntime(10794): ... 11 more
05-01 18:51:48.544: E/AndroidRuntime(10794): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment : make sure class name exists, is public, and has an empty constructor that is public
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-01 18:51:48.544: E/AndroidRuntime(10794): ... 20 more
05-01 18:51:48.544: E/AndroidRuntime(10794): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
05-01 18:51:48.544: E/AndroidRuntime(10794): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-01 18:51:48.544: E/AndroidRuntime(10794): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-01 18:51:48.544: E/AndroidRuntime(10794): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-01 18:51:48.544: E/AndroidRuntime(10794): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
05-01 18:51:48.544: E/AndroidRuntime(10794): ... 23 more

这是我从位于 C:/Program Files/eclipse/SDKs/... 中的现有代码创建 google-service-lib ,然后将其导入到我的项目中时得到的结果:

error loading lib???

有谁知道我还缺少什么吗?我开始对这个简单的事情感到绝望......

最佳答案

您的最小 sdk 为 11。您需要为 12 以下的 api 版本添加支持库

    <uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />

HoneyComb 中引入了 fragment 。因此,为了向后兼容,您需要添加支持库

 android:name="com.google.android.gms.maps.SupportMapFragment "

由于您没有添加支持库,因此出现了 classcastException

要添加支持库,请检查下面的链接

http://developer.android.com/tools/extras/support-library.html

关于java - Google Maps API Android - 膨胀类 fragment 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16322472/

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