java - R.java 没有 R.id.map 的 map

标签 java android eclipse google-maps google-api

所以我正在关注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 key 。显然现在应该可以工作了。

最佳答案

在我看来,第 7 步就是您丢失的资源的来源:

Update res/layout/activity_main.xml and replace the entire contents with

<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)

关于java - R.java 没有 R.id.map 的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16348982/

相关文章:

java - 如何用 unicode 字符替换 String

java - 干净地中断 zeromq 轮询线程

java - Android:尝试切换 Activity 时意外退出

Android + Couchbase 用例?

java - 实现 ISelectionListener 来监视项目资源管理器中选定的项目

java - 如何确定 Java 字段是否具有 transient 修饰符?

java - 从 mvn 依赖项中排除某些依赖项 :resolve

android - 在 Android 应用程序中创建 HTML 内容是个坏主意?

eclipse - Eclipse 工具栏损坏

android - 构建build.gradle文件后无法将Eclipse中的Android项目导入到Android Studio