【发布时间】:2015-03-07 21:08:30
【问题描述】:
我将在 Eclipse 中执行一个简单的地图,但遇到强制关闭错误! 我用 google api v1 没有问题,但是我无法用 google api v2 运行项目!
这是我的 logcat 详细信息:
03-07 23:56:45.755: I/dalvikvm(331): Could not find method android.app.AlertDialog$Builder.<init>, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a
03-07 23:56:45.755: W/dalvikvm(331): VFY: unable to resolve direct method 91: Landroid/app/AlertDialog$Builder;.<init> (Landroid/content/Context;I)V
03-07 23:56:45.764: D/dalvikvm(331): VFY: replacing opcode 0x70 at 0x0037
03-07 23:56:45.764: E/dalvikvm(331): Could not find class 'android.app.Notification$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a
03-07 23:56:45.764: W/dalvikvm(331): VFY: unable to resolve new-instance 40 (Landroid/app/Notification$Builder;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
03-07 23:56:45.774: D/dalvikvm(331): VFY: replacing opcode 0x22 at 0x0029
03-07 23:56:45.774: D/dalvikvm(331): VFY: dead code 0x002b-0071 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.a (ILandroid/content/Context;)V
03-07 23:56:45.794: D/dalvikvm(331): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
03-07 23:56:45.794: W/dalvikvm(331): VFY: unable to resolve instance field 65
03-07 23:56:45.794: D/dalvikvm(331): VFY: replacing opcode 0x52 at 0x0012
03-07 23:56:45.794: D/dalvikvm(331): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
03-07 23:56:45.804: I/dalvikvm(331): Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
03-07 23:56:45.804: W/dalvikvm(331): VFY: unable to resolve virtual method 32: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
03-07 23:56:45.814: D/dalvikvm(331): VFY: replacing opcode 0x6e at 0x0023
03-07 23:56:45.814: D/dalvikvm(331): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;Landroid/support/v4/app/Fragment;ILandroid/content/DialogInterface$OnCancelListener;)Z
03-07 23:56:45.824: D/AndroidRuntime(331): Shutting down VM
03-07 23:56:45.824: W/dalvikvm(331): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-07 23:56:45.854: E/AndroidRuntime(331): FATAL EXCEPTION: main
03-07 23:56:45.854: E/AndroidRuntime(331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mymap/com.example.mymap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.os.Looper.loop(Looper.java:123)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-07 23:56:45.854: E/AndroidRuntime(331): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:56:45.854: E/AndroidRuntime(331): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-07 23:56:45.854: E/AndroidRuntime(331): at dalvik.system.NativeStart.main(Native Method)
03-07 23:56:45.854: E/AndroidRuntime(331): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
03-07 23:56:45.854: E/AndroidRuntime(331): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.Activity.setContentView(Activity.java:1657)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.example.mymap.MainActivity.onCreate(MainActivity.java:18)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-07 23:56:45.854: E/AndroidRuntime(331): ... 11 more
03-07 23:56:45.854: E/AndroidRuntime(331): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 6587000 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-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.common.GooglePlayServicesUtil.D(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.internal.x.T(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.internal.x.S(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.SupportMapFragment$b.nO(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.dynamic.a.a(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2158)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
03-07 23:56:45.854: E/AndroidRuntime(331): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
03-07 23:56:45.854: E/AndroidRuntime(331): ... 19 more
这是我的 main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- This can go anywhere in your layout (see other demos for some examples). -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
我的 MainActivity.java 文件:
package com.example.mymap;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onMapReady(GoogleMap arg0) {
// TODO Auto-generated method stub
}
}
还有我项目的 Manifest.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<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="AIzaSyC82ObRRCXZe_217Z-ovx1VVIpLs-5IvIA"/>
<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>
</application>
</manifest>
请帮帮我,我真的疯了!
【问题讨论】:
-
更改 setContentView(R.layout.activity_main);设置内容视图(R.layout.main);你的 xml 文件被称为 main.xml 正确
标签: android eclipse google-maps