2013-05-02 58 views
0

所以我遵循this指南信(或至少嘗試)。R.java沒有R.id.map的地圖

除了必須導入指南中未指定的一些內容之外,一切都很好,除了我無法解釋的紅色曲線。

在這一行:

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

有下 「地圖」 在 「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; 
    } 
} 

我已經包括Android系統的支持,v4.jar我構建路徑,我已經從谷歌SDK(包括谷歌Play服務)正確下載一切。我也有一個API密鑰。顯然它應該現在工作。

+1

什麼是你的紅色花體說,當你點擊它?你確定你的activity_main.xml佈局文件中有'map'id嗎? – 2013-05-02 22:48:48

回答

1

在我看來,第7步是一個地方你缺少的資源來自:

更新RES /佈局/ 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. 清理項目(再生resoureces,其中R.java)