2013-03-08 155 views
3

我在Google應用中嵌入了Google地圖V2,就像谷歌教程中說的那樣。Android谷歌地圖碎片崩潰

切換到地圖片段時,出現以下錯誤。

03-08 12:52:01.600: E/AndroidRuntime(30314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2105) 

03-08 12:52:01.600: E/AndroidRuntime(30314): FATAL EXCEPTION: main 

03-08 12:52:01.600: E/AndroidRuntime(30314): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.arvidg.exampleactionbartabs/de.arvidg.exampleactionbartabs.StartActivity}: 
java.lang.ClassNotFoundException: de.arvidg.exampleactionbartabs.StartActivity 

繼承人的源代碼

package de.arvidg.exampleactionbartabs; 

import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.maps.MapActivity; 

import data.Device; 
import data.Mission; 
import de.arvidg.exampleactionbartabs.R; 
import logic.FetchData; 
import android.app.Fragment; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.EditText; 

public class MapFrag extends MapFragment { 

    protected FetchData thread; 
    protected Device device; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

     final View lView = inflater.inflate(R.layout.map, container, 
       false); 

     return lView; 

    } 

    public void setDumb() { 

    } 

    public Device getDevice() { 
     return device; 
    } 

    public void setDevice(Device device) { 
     this.device = device; 
    } 

} 


      <?xml version="1.0" encoding="utf-8"?> 
      <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"/> 

我的清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="de.arvidg.exampleactionbartabs" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="14" /> 

    <permission 
     android:name="de.arvidg.exampleactionbartabs.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <uses-permission android:name="de.arvidg.exampleactionbartabs.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".StartActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Holo" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".MapFrag" 
      android:label="Map" 
      android:theme="@android:style/Theme.Holo" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="removed" /> 

     <uses-library android:name="com.google.android.maps" /> 
    </application> 

</manifest> 
+0

您是否在您的項目的'AndroidManifest.xml'中包含了'de.arvidg.exampleactionbartabs.StartActivity'活動? – 2013-03-08 11:59:28

+0

java.lang.ClassNotFoundException:mainfest中的de.arvidg.exampleactionbartabs.StartActivity? – DjHacktorReborn 2013-03-08 12:00:15

+0

您的'MapFrag'不是一個活動,請嘗試從您的清單中刪除它。 – 2013-03-08 12:05:29

回答

1

變化

android:name="com.google.android.gms.maps.MapFragment"/>

android:name="com.google.android.gms.maps.SupportMapFragment"/>activity_main.xml中

,改變

public class MainActivity extends Activity

public class MainActivity extends FragmentActivityMainActivity.java

這兩種修復爲我工作。