首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >R.java没有用于R.id.map的地图

R.java没有用于R.id.map的地图
EN

Stack Overflow用户
提问于 2013-05-03 06:45:45
回答 2查看 1.8K关注 0票数 0

所以我完全按照this的指导来做(或者至少尝试这样做)。

除了必须导入一些指南中没有指定的东西之外,一切都很好,除了有一个我无法解释的红色曲折。

在这一行中:

代码语言:javascript
运行
复制
GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

在"R.id.map“中的"map”下有一个红色标记。

代码语言:javascript
运行
复制
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.*;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GoogleMap map = ((SupportMapFragment)      getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

我已经包含了android-support-v4.jar、我的构建路径,并且我已经从Google SDK正确下载了所有内容(包括Google Play服务)。我也有一个API密钥。显然,它现在应该可以工作了。

EN

Stack Overflow用户

发布于 2019-02-26 18:18:28

如果在activity_main.xml中使用android:id="@+id/activity_main"而不是android:id="@+id/map"。这个错误是可能的。

我也犯了类似的错误。我替换了

代码语言:javascript
运行
复制
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

代码语言:javascript
运行
复制
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16348982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档