我正在努力整理Google Maps Android API V2的实例。我找到了四个教程,描述了如何做到这一点(DJ-android,Vogella,官方文档的2个教程),但没有一个有效。我从其他开发人员那里找到了近十几个帖子,就像这个帖子一样,问题完全相同:“二进制XML文件行#x错误膨胀类”。在stackoverflow上,十几个帖子都没有一个接受的答案。我知道互联网上任何地方都没有这个API的实例。
我的项目内容粘贴在下面。我想我已经从所有这些不同的帖子中推荐了所有内容,但是和其他许多帖子一样,我得到了这个通胀运行时错误。
这个实际项目取自Vogella教程,该教程甚至无法编译。我在同一问题的其他帖子中应用了修复程序。
谁能告诉我如何使这项工作?有谁知道任何地方的工作示例? 谢谢,加里
清单文件......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.vogella.android.locationapi.maps.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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mapdemo.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I have a valid V2 key here" />
</manifest>
我在工作区中有Google Play服务库项目。 。 。
我的主要布局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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.mapdemo.MainActivity"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
MainActivity.java文件。 。 。 (希望代码粘贴在这个论坛上工作)
package com.example.mapdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends android.support.v4.app.FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
Logcat ......(粘贴这些东西有什么秘密吗?)
08-12 13:00:52.380: W/dalvikvm(8118): VFY: unable to resolve instance field 28
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/p/w; (734)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/p/w;' failed
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/ap/as; (6056)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/ap/as;' failed
08-12 13:00:52.550: W/dalvikvm(8118): Unable to resolve superclass of Lmaps/af/k; (5085)
08-12 13:00:52.550: W/dalvikvm(8118): Link of class 'Lmaps/af/k;' failed
08-12 13:00:52.550: E/dalvikvm(8118): Could not find class 'maps.af.k', referenced from method maps.ag.an.a
08-12 13:00:52.550: W/dalvikvm(8118): VFY: unable to resolve new-instance 4928 (Lmaps/af/k;) in Lmaps/ag/an;
08-12 13:00:52.681: W/dalvikvm(8118): threadid=1: thread exiting with uncaught exception (group=0x40017560)
08-12 13:00:52.691: E/AndroidRuntime(8118): FATAL EXCEPTION: main
08-12 13:00:52.691: E/AndroidRuntime(8118): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Looper.loop(Looper.java:130)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 13:00:52.691: E/AndroidRuntime(8118): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 13:00:52.691: E/AndroidRuntime(8118): at java.lang.reflect.Method.invoke(Method.java:507)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
08-12 13:00:52.691: E/AndroidRuntime(8118): at dalvik.system.NativeStart.main(Native Method)
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.Activity.setContentView(Activity.java:1657)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:26)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-12 13:00:52.691: E/AndroidRuntime(8118): ... 11 more
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bb.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bb.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.an.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bi.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at maps.ag.bh.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at blf.onTransact(SourceFile:107)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.os.Binder.transact(Binder.java:279)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh$4.b(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh.a(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.internal.bh.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
08-12 13:00:52.691: E/AndroidRuntime(8118): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-12 13:00:52.691: E/AndroidRuntime(8118): ... 20 more
答案 0 :(得分:2)
我知道互联网上任何地方都没有这个API的实例。
Here are 13 sample projects演示了如何使用Maps V2的各个方面。
我有理由相信,你开始使用的样品中有一些(如果不是全部的话)也可以使用。
谁能告诉我如何使这项工作?
关于:
08-12 13:00:52.691: E/AndroidRuntime(8118): Caused by: java.lang.RuntimeException: API key not found
你得到的是因为你的<meta-data>
元素位置错误。它必须是<application>
元素的子元素:
<?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="8"
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="@style/Theme.Sherlock.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"/>
<activity android:name="LegalNoticesActivity">
</activity>
</application>
</manifest>
例如,Lars Vogel's Maps V2 tutorial将它放在正确的位置。
答案 1 :(得分:1)
我遇到了和你一样的问题......当我将我的SDK更新到4.4 kitkat 时发生了 ..突然间一切都变得混乱了。我对Googlemapv2 apps
非常熟悉,并且我之前开发了很多这些。但是今天我所有的googlemap应用都出现了这个错误
Binary XML file line #x Error inflating class Fragment
每当我运行我编译的应用程序时......我怀疑此错误有4.4次更新。在此次更新之前,vogella
和其他gmapv2
教程没有任何问题。
答案 2 :(得分:0)
将这些元数据标签添加到清单文件
<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" />