简体   繁体   English

Google Maps API Android-错误夸大类片段

[英]Google Maps API Android - Error inflating class fragment

I know that there are many topics on StackOverFlow regarding this problem, however none of them could help me. 我知道在StackOverFlow上有很多与此问题有关的主题,但是它们都无法帮助我。 I am doing a very basic application which I just want to display a MAP. 我正在做一个非常基本的应用程序,我只想显示一个MAP。

  • I Have imported the google-play-services_lib to my main project. 我已经将google-play-services_lib导入到我的主项目中。
  • I have generated my API Key. 我已经生成了我的API密钥。

This is my AndroidManifest.xml file: 这是我的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>

This is my Layout XML file: 这是我的布局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" />

This is my code: 这是我的代码:

public class OpenVenuesMapActivity extends FragmentActivity  {

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

I am running the application on my Sony XPeria J. I get the following Error generated by Loc Cat: 我在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

This is what I get when I create the google-service-lib from existing code, located in my C:/Program Files/eclipse/SDKs/... , and then import it on my project: 这是从现有代码创建google-service-lib时得到的,该代码位于C:/ Program Files / eclipse / SDKs / ...中,然后将其导入到我的项目中:

加载lib时出错???

Does anyone one know What else can I be missing? 有谁知道我还能缺少什么? I am starting to get desperated with this simple thing... 我开始对这个简单的事情感到绝望...

Your min sdk is 11. You will need to add support library for api versions below 12 您的最低SDK为11。您需要为12以下的API版本添加支持库

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

Fragments were introduced in HoneyComb. 片段是在HoneyComb中引入的。 So for backward compatibality you need add support library 因此,为了向后兼容,您需要添加支持库

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

Since you din't add support library you got classcastexception 由于您未添加支持库,因此获得了classcastexception

To add support library check the link below 要添加支持库,请查看下面的链接

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

I Have imported the google-play-services_lib to my main project. 我已经将google-play-services_lib导入到我的主项目中。

Not according to your stack trace. 不根据您的堆栈跟踪。 Your stack trace suggests that you manually modified your build path to include the JAR from the Play Services SDK, rather than attaching the Play Services SDK as an Android library project. 您的堆栈跟踪建议您手动修改构建路径以包括Play Services SDK中的JAR,而不是将Play Services SDK附加为Android库项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM