我正在尝试将 Google Maps Android API V2 的工作示例放在一起。我找到了四个描述如何做到这一点的教程(DJ-android,Vogella,来自官方文档的 2 个教程),但没有一个有效。我从许多其他开发人员那里找到了近十篇类似这篇文章的帖子,它们都存在完全相同的问题:“Binary XML file line #x Error inflating class”。在 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