【问题标题】:R.java doesn't have map for R.id.mapR.java 没有 R.id.map 的地图
【发布时间】:2013-05-02 22:45:44
【问题描述】:

所以我正在关注this 信中指南(或至少尝试这样做)。

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

在这一行:

GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

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

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 密钥。显然它现在应该可以工作了。

【问题讨论】:

  • 当您点击红色曲线时,它会显示什么?你确定你的activity_main.xml布局文件中有'map' id吗?

标签: java android eclipse google-maps google-api


【解决方案1】:

在我看来,第 7 步是您缺少资源的来源:

更新 res/layout/activity_main.xml 并替换全部内容 与

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

在 Eclipse 中,您需要:

  1. 更改文件
  2. 保存
  3. 清理您的项目(以重新生成资源,其中包括 R.java)

【讨论】:

    【解决方案2】:

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

    我得到了类似的错误。我替换了

    <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" />
    

    <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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-01
      • 2015-02-07
      • 1970-01-01
      • 2016-05-28
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多