Java 应用程序已停止!谷歌API V2-地图
我按照youtube上的指示创建了一个地图/位置应用程序。我的第一步只是显示地图,但我被卡住了,因为“不幸的是,MyLoApp已经停止”。我的密码被遵守了。我做错了什么 清单:Java 应用程序已停止!谷歌API V2-地图,java,android,google-maps,google-api,Java,Android,Google Maps,Google Api,我按照youtube上的指示创建了一个地图/位置应用程序。我的第一步只是显示地图,但我被卡住了,因为“不幸的是,MyLoApp已经停止”。我的密码被遵守了。我做错了什么 清单: <manifest xmlns:android="http://schemas.android.com/apk/res/android": package="tri.mylocapp" android:versionCode="1" android:versionNa
<manifest xmlns:android="http://schemas.android.com/apk/res/android":
package="tri.mylocapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<permission
android:name="tri.mylocapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"
/>
<uses-permission android:name="tri.mylocapp.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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDZIavpm2Kcj4QXnb01qxoZqiEXTBXTABw"/>
<activity
android:name="tri.mylocapp.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>
</application>
</manifest>
<?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"/>
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
D/AndroidRuntime(639): Shutting down VM
W/dalvikvm(639): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
E/AndroidRuntime(639): FATAL EXCEPTION: main
E/AndroidRuntime(639): java.lang.RuntimeException: Unable to start activity ComponentInfo{tri.mylocapp/tri.mylocapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime(639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
E/AndroidRuntime(639): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(639): at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(639): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(639): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(639): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(639): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(639): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(639): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(639): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(639): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(639): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime(639): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(639): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime(639): at android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime(639): at tri.mylocapp.MainActivity.onCreate(MainActivity.java:10)
E/AndroidRuntime(639): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(639): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(639): ... 11 more
E/AndroidRuntime(639): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
E/AndroidRuntime(639): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.internal.q.v(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.internal.q.u(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.dynamic.a.a(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
E/AndroidRuntime(639): at android.app.Activity.onCreateView(Activity.java:4242)
E/AndroidRuntime(639): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
E/AndroidRuntime(639): ... 20 more
I/Process(639): Sending signal. PID: 639 SIG: 9
这是MainActivity.java:
package tri.mylocapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
LogCat:
<manifest xmlns:android="http://schemas.android.com/apk/res/android":
package="tri.mylocapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<permission
android:name="tri.mylocapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"
/>
<uses-permission android:name="tri.mylocapp.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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDZIavpm2Kcj4QXnb01qxoZqiEXTBXTABw"/>
<activity
android:name="tri.mylocapp.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>
</application>
</manifest>
<?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"/>
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
D/AndroidRuntime(639): Shutting down VM
W/dalvikvm(639): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
E/AndroidRuntime(639): FATAL EXCEPTION: main
E/AndroidRuntime(639): java.lang.RuntimeException: Unable to start activity ComponentInfo{tri.mylocapp/tri.mylocapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime(639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
E/AndroidRuntime(639): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(639): at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(639): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(639): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(639): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(639): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(639): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(639): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(639): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(639): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(639): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime(639): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(639): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(639): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime(639): at android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime(639): at tri.mylocapp.MainActivity.onCreate(MainActivity.java:10)
E/AndroidRuntime(639): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(639): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(639): ... 11 more
E/AndroidRuntime(639): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
E/AndroidRuntime(639): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.internal.q.v(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.internal.q.u(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.dynamic.a.a(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
E/AndroidRuntime(639): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
E/AndroidRuntime(639): at android.app.Activity.onCreateView(Activity.java:4242)
E/AndroidRuntime(639): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
E/AndroidRuntime(639): ... 20 more
I/Process(639): Sending signal. PID: 639 SIG: 9
D/AndroidRuntime(639):关闭虚拟机
W/dalvikvm(639):线程ID=1:线程退出,但出现未捕获异常(组=0x409961f8)
E/AndroidRuntime(639):致命异常:主
E/AndroidRuntime(639):java.lang.RuntimeException:无法启动活动组件信息{tri.mylocapp/tri.mylocapp.MainActivity}:android.view.InflateException:二进制XML文件行#2:膨胀类片段时出错
E/AndroidRuntime(639):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
E/AndroidRuntime(639):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(639):位于android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(639):位于android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(639):位于android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(639):位于android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(639):位于android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(639):位于java.lang.reflect.Method.Invokenactive(本机方法)
E/AndroidRuntime(639):位于java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(639):位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(639):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(639):位于dalvik.system.NativeStart.main(本机方法)
E/AndroidRuntime(639):由以下原因引起:android.view.InflateException:二进制XML文件行#2:膨胀类片段时出错
E/AndroidRuntime(639):位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
E/AndroidRuntime(639):在android.view.LayoutInflater.inflate(LayoutInflater.java:466)
E/AndroidRuntime(639):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(639):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(639):位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime(639):位于android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime(639):位于tri.mylocapp.MainActivity.onCreate(MainActivity.java:10)
E/AndroidRuntime(639):位于android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(639):位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(639):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(639):。。。还有11个
E/AndroidRuntime(639):由以下原因引起:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。预期为4242000,但找到0。元素中必须有以下声明:
E/AndroidRuntime(639):位于com.google.android.gms.common.GooglePlayServicesUtil.n(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.common.GooglePlayServicesUtil.isgoogleplayservicesavaailable(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.internal.q.v(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.internal.q.u(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.mapsintializer.initialize(未知源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.MapFragment$b.ex(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.MapFragment$b.a(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.dynamic.a.a(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.dynamic.a.onInflate(未知来源)
E/AndroidRuntime(639):位于com.google.android.gms.maps.MapFragment.onInflate(未知来源)
E/AndroidRuntime(639):位于android.app.Activity.onCreateView(Activity.java:4242)
E/AndroidRuntime(639):位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
E/AndroidRuntime(639):。。。20多
I/处理(639):发送信号。PID:639信号:9
在清单中声明您的活动时,将locap更改为locapp您的日志清楚地表明
.818: E/AndroidRuntime(639): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
03-20 17:11:43.818:icesUtil.isGooglePlayServicesAvailable(Unknown
这是因为最新的google play服务需要一个版本名,在AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
构建您的manifest.xml如下:
....<application>
..............
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDrcKDGxUgl0Ps4u2ptOsIUCI6ooXmZ0RU" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
。。。。
..............
在我将locap修复到locapp后,它仍然不工作。我将更新logcat。清单已修复,logcat已更新。应用程序仍然无法运行。请添加一个元数据,指定您正在使用的播放服务的版本,并且它应该能够正常工作。可能的代码副本确实解决了我的问题,解决了“已停止”的问题,谢谢。然而,我的应用程序启动了,但它不显示地图(它显示地图的屏幕,但没有内容)。无论如何,我会为这个问题发布另一个问题。