我是Android开发人员的新手。我正在使用Android Studio 1.0.2,我正在构建一个非常简单的应用程序来显示Mapview。
我尝试按照几个教程来实现它,但我总是遇到同样的问题。应用程序崩溃时出现以下错误:
12-29 18:47:41.182 3574-3574/com.example.sebastien.myfirstandroidapp D/AndroidRuntime﹕ Shutting down VM
12-29 18:47:41.183 3574-3574/com.example.sebastien.myfirstandroidapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.sebastien.myfirstandroidapp, PID: 3574
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sebastien.myfirstandroidapp/com.example.sebastien.myfirstandroidapp.MapActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
布局仅包含以下内容:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/mapView"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我还有一个错误:
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 6171000 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" /> at com.google.android.gms.common.GooglePlayServicesUtil.E(Unknown Source) at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
我将非常感谢任何帮助或想法进行调查,以使这个简单的应用程序运行。
答案 0 :(得分:0)
我将非常感谢任何帮助或想法进行调查,以使这个简单的应用程序运行
在错误中给了你一些非常具体的建议:
The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 6171000 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" />
这将为您提供类似于以下内容的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.mapsv2.basic"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16"/>
<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_NETWORK_STATE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
<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>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC4iyT46cB00IdKGcy5EmAxK5uCOQX2Oy8"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name="LegalNoticesActivity">
</activity>
</application>
</manifest>