当我运行Google地图应用程序时,会出现此错误消息并关闭应用程序:
不幸的是ggmaps已经停止了。
我无法弄清楚出了什么问题。有人能告诉我我做错了吗?
MainActivity.java
package com.example.ggmaps;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
activity_main
<?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.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
清单(更新)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ggmaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.ggmaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.ggmaps.permission.MAPS_RECEIVE" />
<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="4452000" />
<activity
android:name="com.example.ggmaps.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCLNoY5xaeZJuYBA3vTI3oua3lrsstUMjk"
/>
</application>
</manifest>
logcat的
08-05 10:16:30.425: E/AndroidRuntime(9818): FATAL EXCEPTION: main
08-05 10:16:30.425: E/AndroidRuntime(9818): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ggmaps/com.example.ggmaps.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread.access$700(ActivityThread.java:150)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.os.Looper.loop(Looper.java:137)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread.main(ActivityThread.java:5279)
08-05 10:16:30.425: E/AndroidRuntime(9818): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 10:16:30.425: E/AndroidRuntime(9818): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-05 10:16:30.425: E/AndroidRuntime(9818): at dalvik.system.NativeStart.main(Native Method)
08-05 10:16:30.425: E/AndroidRuntime(9818): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:342)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.Activity.setContentView(Activity.java:1928)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.example.ggmaps.MainActivity.onCreate(MainActivity.java:18)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.Activity.performCreate(Activity.java:5267)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
08-05 10:16:30.425: E/AndroidRuntime(9818): ... 11 more
08-05 10:16:30.425: E/AndroidRuntime(9818): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 4452000. 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" />
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.common.GooglePlayServicesUtil.x(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.internal.u.F(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.internal.u.E(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.MapFragment$b.ju(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.dynamic.a.a(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.app.Activity.onCreateView(Activity.java:4869)
08-05 10:16:30.425: E/AndroidRuntime(9818): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
08-05 10:16:30.425: E/AndroidRuntime(9818): ... 21 more
08-05 10:16:30.746: E/android.os.Debug(2381): !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
08-05 10:16:30.926: E/dalvikvm(2381): The following issues were seen:
08-05 10:16:36.805: E/EnterpriseContainerManager(2381): ContainerPolicy Service is not yet ready!!!
08-05 10:16:39.576: E/ActivityThread(9959): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@2125d9c8 that was originally bound here
08-05 10:16:39.576: E/ActivityThread(9959): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@2125d9c8 that was originally bound here
08-05 10:16:39.576: E/ActivityThread(9959): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:974)
08-05 10:16:39.576: E/ActivityThread(9959): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:868)
08-05 10:16:39.576: E/ActivityThread(9959): at android.app.ContextImpl.bindService(ContextImpl.java:1757)
08-05 10:16:39.576: E/ActivityThread(9959): at android.app.ContextImpl.bindService(ContextImpl.java:1746)
08-05 10:16:39.576: E/ActivityThread(9959): at android.content.ContextWrapper.bindService(ContextWrapper.java:480)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:158)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:146)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.emailcommon.service.AccountServiceProxy.restoreAccountsIfNeeded(AccountServiceProxy.java:135)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.exchange.ExchangeService$11.run(ExchangeService.java:4575)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:986)
08-05 10:16:39.576: E/ActivityThread(9959): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:983)
08-05 10:16:39.576: E/ActivityThread(9959): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-05 10:16:39.576: E/ActivityThread(9959): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-05 10:16:39.576: E/ActivityThread(9959): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-05 10:16:39.576: E/ActivityThread(9959): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-05 10:16:39.576: E/ActivityThread(9959): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-05 10:16:39.576: E/ActivityThread(9959): at java.lang.Thread.run(Thread.java:856)
08-05 10:16:52.196: E/Watchdog(2381): !@Sync 105
08-05 10:17:22.195: E/Watchdog(2381): !@Sync 106
08-05 10:17:52.196: E/Watchdog(2381): !@Sync 107
08-05 10:18:22.196: E/Watchdog(2381): !@Sync 108
答案 0 :(得分:3)
请在manifest.xml中添加此元标记
<meta-data
android:name="com.google.android.gms.version"
android:value="5077000" />
答案 1 :(得分:0)
尝试添加此行:
<permission
android:name="com.example.ggmaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
在您的清单文件中。
答案 2 :(得分:0)
在application
标记
<meta-data
android:name="com.google.android.gms.version"
android:value="4452000" />
这些权限位于application
标记
<permission
android:name="com.example.ggmaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.ggmaps.permission.MAPS_RECEIVE" />