即使我添加了必需的密钥,元数据和权限以及允许使用OpenGL的uses-feature标记,Google Maps API也会继续崩溃。我真的很茫然,所以请查看我的清单,看看是否有遗漏或不正确的东西。我也谢谢你
//清单
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.googlemapapp"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="20" />
<permission
android:name="com.example.googlemapapp.maps.permission.MAPS_RECIEVE"
android:protectionLevel ="signature"/>
<uses-permission android:name="com.example.googlemapapp.permission.MAPS_RECEIVE" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_API_KEY_HERE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</activity>
</application>
</manifest>
// activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.googlemapapp.MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:src="@drawable/a" />
<EditText
android:id="@+id/editText1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_toRightOf="@+id/imageView1"
android:ems="10" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignLeft="@+id/imageView1"
android:src="@drawable/b" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/editText2"
android:layout_below="@+id/button1"
android:ems="10"
android:inputType="textMultiLine" />
<EditText
android:id="@+id/editText2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="15dp"
android:ems="10" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:text="Enter Data below"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText3"
android:layout_below="@+id/editText2"
android:layout_toRightOf="@+id/imageView2"
android:text="Search" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="600dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
// MainActivity.java
package com.example.googlemapapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class MainActivity extends FragmentActivity {
EditText TXTA, TXTB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TXTA = (EditText) findViewById(R.id.editText1);
TXTB = (EditText) findViewById(R.id.editText2);
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
// logcat的
12-05 02:15:33.250: E/AndroidRuntime(2247): FATAL EXCEPTION: main
12-05 02:15:33.250: E/AndroidRuntime(2247): Process: com.example.googlemapapp, PID: 2247
12-05 02:15:33.250: E/AndroidRuntime(2247): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapapp/com.example.googlemapapp.MainActivity}: android.view.InflateException: Binary XML file line #78: Error inflating class fragment
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread.access$800(ActivityThread.java:138)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.os.Handler.dispatchMessage(Handler.java:102)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.os.Looper.loop(Looper.java:136)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread.main(ActivityThread.java:5026)
12-05 02:15:33.250: E/AndroidRuntime(2247): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 02:15:33.250: E/AndroidRuntime(2247): at java.lang.reflect.Method.invoke(Method.java:515)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-05 02:15:33.250: E/AndroidRuntime(2247): at dalvik.system.NativeStart.main(Native Method)
12-05 02:15:33.250: E/AndroidRuntime(2247): Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class fragment
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.Activity.setContentView(Activity.java:1930)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.example.googlemapapp.MainActivity.onCreate(MainActivity.java:16)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.Activity.performCreate(Activity.java:5242)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
12-05 02:15:33.250: E/AndroidRuntime(2247): ... 11 more
12-05 02:15:33.250: E/AndroidRuntime(2247): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.common.GooglePlayServicesUtil.E(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.internal.u.T(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.internal.u.S(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.SupportMapFragment$b.mA(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2158)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
12-05 02:15:33.250: E/AndroidRuntime(2247): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-05 02:15:33.250: E/AndroidRuntime(2247): ... 21 more
12-05 02:15:37.120: I/Process(2247): Sending signal. PID: 2247 SIG: 9
答案 0 :(得分:1)
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
当前位于清单中的活动元素内。您需要直接在application元素中移动它。这个块同样适用:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_API_KEY_HERE" />