我的Google Map V2没有为我的Nexus 5加载

时间:2014-05-07 11:56:56

标签: android google-maps

这是我的AndroidManifest

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

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="19" />

<permission
     android:name="com.pmss.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
<uses-permission android:name="com.pmss.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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/Theme.AppCompat.Light.DarkActionBar" >

    <activity
        android:name="com.pmss.SplashScreen"
        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="com.pmss.Login"
        android:label="@string/app_main" >
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.pmss.Register"
        android:label="@string/button_register"
        android:parentActivityName="com.pmss.Login" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Login" />
    </activity>
    <activity
        android:name="com.pmss.MainMenu"
        android:label="@string/title_activity_main_menu"
        android:parentActivityName="com.pmss.Login" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Login" />
    </activity>
    <activity
        android:name="com.pmss.UserInfo"
        android:label="@string/title_activity_user_info"
        android:parentActivityName="com.pmss.MainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.MainMenu" />
    </activity>
    <activity
        android:name="com.pmss.Payment"
        android:label="@string/title_activity_payment"
        android:parentActivityName="com.pmss.MainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.MainMenu" />
    </activity>
    <activity
        android:name="com.pmss.TrackParcel"
        android:label="@string/title_activity_track_parcel"
        android:parentActivityName="com.pmss.MainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.MainMenu" />
    </activity>
    <activity
        android:name="com.pmss.TrackMap"
        android:label="@string/title_activity_track_map"
        android:parentActivityName="com.pmss.TrackParcel" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.TrackParcel" />
    </activity>
    <activity
        android:name="com.pmss.CheckCard"
        android:label="@string/title_activity_check_card"
        android:parentActivityName="com.pmss.MainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.MainMenu" />
    </activity>
    <activity
        android:name="com.pmss.RequestService"
        android:label="@string/title_activity_request_service"
        android:parentActivityName="com.pmss.MainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.MainMenu" />
    </activity>
    <activity
        android:name="com.pmss.StaffMainMenu"
        android:label="@string/title_activity_main_menu"
        android:parentActivityName="com.pmss.Login" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Login" />
    </activity>
    <activity
        android:name="com.pmss.StaffInfo"
        android:label="@string/title_activity_staff_info"
        android:parentActivityName="com.pmss.StaffMainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.StaffMainMenu" />
    </activity>
    <activity
        android:name="com.pmss.FulfillRequest"
        android:label="@string/title_activity_fulfill_request"
        android:parentActivityName="com.pmss.StaffMainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.StaffMainMenu" />
    </activity>
    <activity
        android:name="com.pmss.OnlinePayment"
        android:label="@string/title_activity_online_payment"
        android:parentActivityName="com.pmss.Payment" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Payment" />
    </activity>
    <activity
        android:name="com.pmss.CardPayment"
        android:label="@string/title_activity_card_payment"
        android:parentActivityName="com.pmss.Payment" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Payment" />
    </activity>
    <activity
        android:name="com.pmss.CashPayment"
        android:label="@string/title_activity_cash_payment"
        android:parentActivityName="com.pmss.Payment" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.Payment" />
    </activity>
    <activity
        android:name="com.pmss.StaffTrackParcel"
        android:label="@string/title_activity_staff_track_parcel"
        android:parentActivityName="com.pmss.StaffMainMenu" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.pmss.StaffMainMenu" />
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

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

这是我的activity_track_map.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.pmss.TrackMap"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
 </RelativeLayout>

这是我的TrackMap.java

@SuppressLint("NewApi")
public class TrackMap extends FragmentActivity{

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

        return inflater.inflate(R.layout.activity_track_map, container, false);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_track_map);

        GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();



}

这是我的Login.java

public class Login extends ActionBarActivity implements OnClickListener {

    private Button login, register;
    private EditText email, password;

    JSONArray loginposition = null;
    // Progress Dialog
    private ProgressDialog pDialog;

    // JSON parser class
    JSONParser jsonParser = new JSONParser();


    private static final String LOGIN_URL = "http://XXX.XXX.X.XX:1234/PMSS/login.php";


    // JSON element ids from repsonse of php script:
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_MESSAGE = "message";
    private static final String TAG_POSTS = "posts";
    private static final String TAG_EMAIL = "email";
    private static final String TAG_POSITION = "position";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        /*this.requestWindowFeature(Window.FEATURE_NO_TITLE);*/

        setContentView(R.layout.activity_login);
        login = (Button) findViewById(R.id.login);
        register = (Button) findViewById(R.id.registerlauncher);
        email = (EditText) findViewById(R.id.useridlogin);
        password = (EditText) findViewById(R.id.passwordlogin);

        login.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String Username = email.getText().toString();
                String Password = password.getText().toString();
                new AttemptLogin(Username, Password).execute();
            }
        });

        register.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Login.this, TrackMap.class);
                //Clear activity before this
                //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);

            }
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // For the main activity, make sure the app icon in the action bar
            // does not behave as a button
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);

        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        default:
            break;
        }
    }

}

logcat的

05-07 19:53:01.619: E/AndroidRuntime(26477): FATAL EXCEPTION: main
05-07 19:53:01.619: E/AndroidRuntime(26477): Process: com.pmss, PID: 26477
05-07 19:53:01.619: E/AndroidRuntime(26477): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pmss/com.pmss.TrackMap}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.os.Looper.loop(Looper.java:136)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread.main(ActivityThread.java:5017)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at java.lang.reflect.Method.invokeNative(Native Method)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at java.lang.reflect.Method.invoke(Method.java:515)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at dalvik.system.NativeStart.main(Native Method)
05-07 19:53:01.619: E/AndroidRuntime(26477): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.Activity.setContentView(Activity.java:1929)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.pmss.TrackMap.onCreate(TrackMap.java:25)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.Activity.performCreate(Activity.java:5231)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-07 19:53:01.619: E/AndroidRuntime(26477):    ... 11 more
05-07 19:53:01.619: E/AndroidRuntime(26477): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.internal.q.B(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.internal.q.A(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.dynamic.a.a(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-07 19:53:01.619: E/AndroidRuntime(26477):    ... 21 more

在我的编码中,我临时链接我的注册按钮以启动Activity(TrackMap.class)。我不知道谷歌地图v2为什么不能加载到我的Nexus 5设备中,我只有Nexus 5设备和我一起寻求帮助。我非常感谢你的帮助

2 个答案:

答案 0 :(得分:1)

你的logcat清楚地说了

: Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-07 19:53:01.619: E/AndroidRuntime(26477):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)

您需要在manifest.xml文件中使用Google play services version标记下的<meta-data>标记添加<application>,例如

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

让你的manifest.xml赞成

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

 <meta-data android:name="com.google.android.gms.version"  
 android:value="@integer/google_play_services_version" />

</application>

你也应该改变这个

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

使用

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

答案 1 :(得分:0)

您尚未为googlePlayService添加元数据。 在<Application>内,添加以下代码

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

请参阅以下代码以便更好地理解。

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.AT4U.deepak_anand.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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