0

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.

4

2 回答 2

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)
于 2013-05-02T22:56:41.443 回答
1

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

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

<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" />
于 2019-02-26T10:18:27.523 回答