【问题标题】:Android support library v4 and Google Maps API breaks compilationAndroid 支持库 v4 和 Google Maps API 中断编译
【发布时间】:2012-12-22 13:57:42
【问题描述】:

我正在尝试在针对 v10 API 的 android 项目中使用 Google Maps API v2。 阅读开发指南据说,由于 Fragments 只在 android api 11 中引入,我需要使用 Android Support Library 来使用 API。

所以我做了以下事情:
- 将 android 支持库 v4 jar 包含到我的项目中
- 包含“google-play-services-lib”库项目并引用它
- 编写了以下代码,取自开发指南:

package com.darco.darcoapp;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

public class CardJourneyActivity extends FragmentActivity{
    private GoogleMap myGoogleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_card_journey);

        FragmentManager fm = getSupportFragmentManager();
        Fragment fr = fm.findFragmentById(R.id.mapFragmentCardJourney);
        MapFragment mf = (MapFragment)fr; //this line causes the compilation error

    }

正如注释所指出的,问题出现在代码的最后一行。 当我添加 Eclipse 中出现以下错误时(不在该行,而是在文件顶部):

The type android.app.Fragment cannot be resolved. It is indirectly referenced from required .class files

而 Eclipse 拒绝编译该项目。

我已经尝试了在项目设置中我能想到的所有可能的配置,但也许有些东西让我无法理解......我做错了什么?我在网上找到了一些有类似问题但没有解决方案,或者至少他们提出的解决方案对我没有用。

【问题讨论】:

    标签: android eclipse google-maps-api-2 android-support-library


    【解决方案1】:

    当您使用 Android 支持包的片段反向移植时,请使用 SupportMapFragment,而不是 MapFragment

    【讨论】:

    • 如此简单,但不知道我被难住了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多