2013-08-16 18 views
0

我試圖在新片段中添加Google地圖。但是,我得到這個錯誤:在我的片段中添加Google地圖

08-16 16:58:37.334:E/AndroidRuntime(15409):致命異常:主要 08-16 16:58:37.334:E/AndroidRuntime(15409): android.view.InflateException:二進制XML文件行#2:Error inflate class fragment 08-16 16:58:37.334:E/AndroidRuntime(15409): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710 ) 08-16 16:58:37.334:E/AndroidRuntime(15409):在 android.view.LayoutInflater.inflate(LayoutInflater.java:467)

這裏是啓動片段代碼:

Fragment fragment1 = new MapsFragment(); 
    //fragment.setArguments(arguments); 
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); 
    fragmentTransaction.replace(R.id.content_frame, fragment1); 
    fragmentTransaction.addToBackStack(null); 
    fragmentTransaction.commit(); 

這裏是我的MapsFragment的代碼:

import com.rss.main.MainActivity; 

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class MapsFragment extends Fragment { 

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

     LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     View view = (View) mInflater.inflate(R.layout.maps_view, null); 

//  MainActivity.setShareButtonToVisible(); 
//  MainActivity.setElevatorButtonToInVisible(); 

     return view; 
    } 

    @Override 
    public void onDestroyView() { 
     MainActivity.setShareButtonToInVisible(); 
     super.onDestroyView(); 
    } 


} 

這裏是我的maps_view.xml的代碼:

<?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" 
      android:name="com.google.android.gms.maps.MapFragment"/> 

問題在哪裏?

感謝

+0

請參閱本也許略知一二http://mobile.tutsplus.com/tutorials/android/android-sdk-working -with-谷歌-MAPS-應用建立/ – Aravin

回答

0

你Mainactivty應該延伸FragmentActivity 谷歌播放服務檢查是否即時拍攝