R.java不具有的地图为R.id.map [英] R.java doesn't have map for R.id.map

查看:328
本文介绍了R.java不具有的地图为R.id.map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我下面的指南信(或至少试图)

和除了有导入指南中没有指定一些东西,一切都很好,除非有一个红色的波浪线,我无法解释。

在这一行:

  GoogleMap的地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。

有在地图中的R.id.map红色标记。

 进口com.google.android.gms.common.GooglePlayServicesUtil;
进口com.google.android.gms.maps *。进口android.os.Bundle;
进口android.app.Activity;
进口android.support.v4.app.FragmentActivity;
进口android.view.Menu;公共类MainActivity扩展FragmentActivity {   @覆盖
   保护无效的onCreate(捆绑savedInstanceState){
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        使用GoogleMap地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap();
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }
}

我已经包括Android的支持,v4.jar我构建路径,我已经从谷歌SDK正确下载的一切(包括谷歌播放服务)。我有一个API密钥了。显然,它现在应该工作。


解决方案

在我看来,第7步是一个你在哪里丢失的资源来自:


  

更新RES /布局/ activity_main.xml中并更换全部内容
  以


 <片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:ID =@ + ID /图的an​​droid:layout_width =match_parent
 机器人:layout_height =match_parent
 类=com.google.android.gms.maps.SupportMapFragment/>

在Eclipse中你需要:


  1. 更改文件

  2. 保存它

  3. 清理项目(重新生成resoureces,其中R.java)

So I'm following this guide TO THE LETTER (or at least trying to).

And aside from having to import some things not specified in the guide, everything is fine EXCEPT there is a red squiggle that I can't explain.

In this line:

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

there is a red mark under "map" in "R.id.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;
    }
}

I have already included android-support-v4.jar my buildpath and I have downloaded everything correctly from the Google SDK (including Google Play services). I have an API key too. Apparently it should be working by now.

解决方案

Seems to me that Step 7 is the one where your missing resource comes from:

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

In Eclipse you need to:

  1. Change the file
  2. Save it
  3. Clean your project (to regenerate the resoureces, among them R.java)

这篇关于R.java不具有的地图为R.id.map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆