我正在尝试构建地图应用程序,并逐步遵循此链接。我在这里找到了类似的主题,但对我没有帮助。我想显示地图,但当我运行它时,它会返回强制关闭和我的android设备。我看到了很多关于这个错误的问题,但没有人真正回答我的问题。这是我的LogCat:
03-21 20:55:57.476:D/AndroidRuntime(4090):关闭虚拟机03-21 20:55:57.476:W/dalvikvm(4090):线程ID=1:线程退出,出现未捕获的异常(组=0x417692a0)03-21 20:55:57.500:E/AndroidRuntime(4090):致命异常:main03-21 20:55:57.500:E/AndroidRuntime(4090):java.lang.RuntimeException:无法启动活动ComponentInfo{com.example.mapaandroid.com/example.mapandroid.MainActivity}:android.view.InflateException:二进制XML文件行#11:膨胀类片段时出错03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread.performLaunchActivity(ActivityThreads.java:2097)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread.handleLaunchActivity(ActivityThreads.java:2122)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread.access上$600(ActivityThreads.java:140)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread$H.handleMessage(ActivityThreads.java:1228)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.os.Handler.dispatchMessage(Handler.java:99)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.os.Looper.loop(Looper.java:137)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread.main(ActivityThreads.java:4895)03-21 20:55:57.500:E/AndroidRuntime(4090):在java.lang.reflect.Method.invokeNative(Native Method)03-21 20:55:57.500:E/AndroidRuntime(4090):在java.lang.reflect.Method.ioke(Method.java:511)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteIndit.java:994)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.android.internal.os.ZygoteInit.main(ZygoteNit.java:761)03-21 20:55:57.500:E/AndroidRuntime(4090):在dalvik.system.NativeStart.main(Native方法)03-21 20:55:57.500:E/AndroidRuntime(4090):由以下原因引起:android.view.InflateException:二进制XML文件行#11:膨胀类片段时出错03-21 20:55:57.500:E/AndroidRuntime(4090):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.view.LayoutInflater.inflature(LayoutInflater.java:489)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.view.LayoutInflater.inflature(LayoutInflater.java:396)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.example.mapaandroid.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:67)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.Frage.performCreateView(Fragment.java:1500)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.FragageManagerImpl.moveToState(FragmentManager.java:927)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.FragageManagerImpl.moveToState(FragmentManager.java:1104)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.FragageManagerImpl.execPendingActions(FragmentManager.java:1467)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.FrageActivity.onStart(FragmentActivity.java:570)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.Activity.performStart(Activity.java:5173)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.app.ActivityThread.performLaunchActivity(ActivityThreads.java:2070)03-21 20:55:57.500:E/AndroidRuntime(4090):。。。11个以上03-21 20:55:57.500:E/AndroidRuntime(4090):由java.lang.IllegalStateException引起:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。应为4242000,但找到0。元素中必须具有以下声明:03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.common.GooglePlayServicesUtil.n(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.internal.q.v(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.internal.q.u(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.MapsInitializer.initialize(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.SupportMapFragment$b.ex(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.SupportMapFragment$b.a(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.dynamic.a.a(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.dynamic.a.onInflate(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在com.google.android.gms.maps.SupportMapFragment.oInflate(未知来源)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.support.v4.app.FragageActivity.onCreateView(FragmentActivity.java:290)03-21 20:55:57.500:E/AndroidRuntime(4090):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)03-21 20:55:57.500:E/AndroidRuntime(4090):。。。24个以上03-21 20:55:57.515:D/dalvikvm(4090):GC_CONCURRENT释放233K,10%释放7615K/8455K,暂停13ms+2ms,总计39ms03-21 21:36:53.75:W/dalvikvm(4279):VFY:无法解析Lcom/google/android/gms/R$styleable中的静态字段3202(MapAttrs);03-21 21:36:53.75:D/dalvikvm(4279):VFY:在0x000e处替换操作码0x6203-21 21:36:53.375:D/AndroidRuntime(4279):关闭VM03-21 21:36:53.75:W/dalvikvm(4279):threadid=1:线程退出,出现未捕获异常(组=0x417692a0)03-21 21:36:53.382:E/AndroidRuntime(4279):致命异常:main03-21 21:36:53.882:E/AndroidRuntime(4279):java.lang.NoClassDefFoundError.com.google.android.gms.R$样式03-21 21:36:53.882:E/AndroidRuntime(4279):在com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(未知来源)03-21 21:36:53.882:E/AndroidRuntime(4279):在com.google.android.gms.maps.SupportMapFragment.oInflate(未知来源)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.support.v4.app.FrageActivity.onCreateView(FragmentActivity.java:290)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.view.LayoutInflater.inflature(LayoutInflater.java:489)03-21 21:36:53.382:E/AndroidRuntime(4279):在android.view.LayoutInflater.inflature(LayoutInflater.java:396)03-21 21:36:53.882:E/AndroidRuntime(4279):在com.example.map.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:57)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.support.v4.app.Frage.performCreateView(Fragment.java:1500)03-21 21:36:53.382:E/AndroidRuntime(4279):在android.support.v4.app.FragageManagerImpl.moveToState(FragmentManager.java:927)03-21 21:36:53.382:E/AndroidRuntime(4279):在android.support.v4.app.FragageManagerImpl.moveToState(FragmentManager.java:1104)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.support.v4.app.FragageManagerImpl.execPendingActions(FragmentManager.java:1467)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.support.v4.app.FrageActivity.onStart(FragmentActivity.java:570)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.Activity.performStart(Activity.java:5173)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.ActivityThread.performLaunchActivity(ActivityThreads.java:2070)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.ActivityThread.handleLaunchActivity(ActivityThreads.java:2122)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.ActivityThread.access$600(ActivityThreads.java:140)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.ActivityThread$H.handleMessage(ActivityThreads.java:1228)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.os.Handler.dispatchMessage(Handler.java:99)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.os.Looper.loop(Looper.java:137)03-21 21:36:53.882:E/AndroidRuntime(4279):在android.app.ActivityThread.main(ActivityThreads.java:4895)03-21 21:36:53.882:E/AndroidRuntime(4279):位于java.lang.reflect.Method.invokeNative(Native Method)03-21 21:36:53.882:E/AndroidRuntime(4279):在java.lang.reflect.Method.ioke(Method.java:511)03-21 21:36:53.882:E/AndroidRuntime(4279):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)03-21 21:36:53.882:E/AndroidRuntime(4279):在com.android.internal.os.ZygoteInit.main(ZygoteNit.java:761)03-21 21:36:53.882:E/AndroidRuntime(4279):在dalvik.system.NativeStart.main(Native Method)
和这里我的MainActivity.java
包com.example.map;导入android.support.v4.app.Fragment;导入android.support.v4.app.FragmentActivity;导入android.os.Bundle;importandroid.view.LayoutInflater;导入android.view.Menu;导入android.view.MenuItem;导入android.view.view;导入android.view.ViewGroup;公共类MainActivity扩展FragmentActivity{@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if(savedInstanceState==null){getSupportFragmentManager().beginTransaction().add(R.id.container,new Placeholder Fragment()).commit();}}@Override公共布尔值onCreateOptionsMenu(菜单菜单){//给菜单充气;这会将项目添加到操作栏中(如果存在)。getMenuInflater().flupt(R.menu.main,menu);返回true;}@Override公共布尔值onOptionsItemSelected(MenuItem项){//处理操作栏项目单击此处。操作栏将//自动处理"主页/向上"按钮上的单击,只要//在AndroidManifest.xml中指定父活动。int id=item.getItemId();if(id==R.id.action_settings){返回true;}return super.onOptionsItemSelected(item);}/***包含一个简单视图的占位符片段。*/公共静态类PlaceholderFragment扩展Fragment{public占位符Fragment(){}@Overridepublic View onCreateView(布局充气器充气器、ViewGroup容器、,Bundle savedInstanceState){View rootView=充气机.充气(R.layout.fragment_main,容器,false);return rootView;}}}
这是我的activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.map.MainActivity"
tools:ignore="MergeRootFrame" />
这是我的fragment_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: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.map.MainActivity$PlaceholderFragment" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
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.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="0123456789abcde" />
<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" >
<activity
android:name="com.example.map.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>
我已经一步一步地阅读了下面的链接,但我的代码中似乎有很多错误。我想念什么?有什么建议吗?非常感谢。
移动此
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="0123456789abcde" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
到您的<应用程序><application>标记。
com.google.android.gms.R$样式化
这通常是由于没有正确引用谷歌播放服务
由java.lang.IollegalStateException引起:应用程序的AndroidManifest.xml没有正确的值。预期4242000,但找到0。您必须在元素:
作为清单文件的应用程序标记的子项,您还缺少2个元标记
<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="your api key"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.map.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>
在android中编写@integer/google_play_services_version是正确的价值观
是。检查库项目的res/values中的version.xml
。将如下所示。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
你所需要做的就是引用与相同的内容
android:value="@integer/google_play_services_version" />
// this is what should be in the application tag of manifest file