所以我正在关注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 中您需要:
- 更改文件
- 保存
- 清理您的项目(以重新生成资源,其中包括 R.java)
关于java - R.java 没有 R.id.map 的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16348982/