我遇到以下問題: 當我按下按鈕時,我的主要活動啓動了一個FragmentActivity
,這意味着要使用Google庫來顯示以第一個活動傳遞的座標爲中心的地圖。 現在,我在FragmentActivity
中放了幾條Log.i行,看起來它的onCreate
方法被調用,並且在嘗試設置活動的ContentView
時發生崩潰。 這裏的代碼,我叫FragmentActivity
塊,稱爲ShowMap:啓動GoogleMaps時應用程序崩潰FragmentActivity
mbtMap.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
Intent aprimappa = new Intent(MyCoordinates.this,ShowMap.class);
Bundle catasta = new Bundle();
catasta.putDouble("lat", Lati);
catasta.putDouble("lon", Longi);
aprimappa.putExtras(catasta);
Log.i(TAG, "Intento preparato. Chiamo ShowMap.");
startActivity(aprimappa);
}
});
這是我的
ShowMap.class的第一位:
public class ShowMap extends FragmentActivity{
final static String TAG="thereyouwere";
private GoogleMap googlemap;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Log.i(TAG, "Siamo nell'onCreate di ShowMap.");
setContentView(R.layout.activity_show_map);
Log.i(TAG,"Caricato layout di ShowMap.");
Bundle b = getIntent().getExtras();
double lat=b.getDouble("lat");
double lon=b.getDouble("lon");
如果您需要它,這裏也是我的AndroidManifest.XML
和xml佈局
ShowMap:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.paquito.thereyouwere"
android:versionCode="1"
android:versionName="1.0" >
<!-- Google Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***********************" />
<permission
android:name="it.paquito.thereyouwere.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="it.paquito.thereyouwere.MyCoordinates"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ShowMap"></activity>
</application>
</manifest>
和
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
預先感謝您的任何幫助,您可以給我!
能否請您補充提logcat的? – donfuxx