Android地图应用V2崩溃 [英] Android Maps V2 App Crashing

查看:145
本文介绍了Android地图应用V2崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用谷歌Android地图API V2的应用程序,我按照谷歌提供的指南中的每一步,但它不unfortunely工作,它崩溃每次我试图启动它的时间。所以,我想知道这是什么问题?

MainActivity.java

 包com.android.maptest;进口android.app.Activity;
进口android.os.Bundle;公共类MainActivity延伸活动{    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }
}

activity_main.xml中

 <?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          机器人:ID =@ + ID /图
          机器人:layout_width =match_parent
          机器人:layout_height =match_parent
          机器人:名字=com.google.android.gms.maps.MapFragment/>

Maptest的Manifest.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.android.maptest
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =16
        机器人:targetSdkVersion =16/>
    <许可
        机器人:名字=com.android.maptest.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名/>    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>    <使用许可权的android:NAME =com.android.maptest.permission.MAPS_RECEIVE/>
    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme
        机器人:可调试=真正的>
        <活动
            机器人:名字=com.android.maptest.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        &所述;元数据
            机器人:名字=com.google.android.maps.v2.API_KEY
            机器人:值=API_KEY/>
    < /用途>< /清单>

的logcat

  9月3日至一十二日:46:13.150:D / AndroidRuntime(1547):关闭VM9月3日至12日:46:13.150:W / dalvikvm(1547):主题ID = 1:螺纹未捕获的异常(组= 0x410e22a0)退出9月3日至12日:46:13.155:E / AndroidRuntime(1547):致命异常:主要9月3日至12日:46:13.155:E / AndroidRuntime(1547):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.android.maptest / com.android.maptest.MainActivity}:android.view.InflateException:二进制XML文件行#2:错误充气类片段9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在

android.app.ActivityThread.access $ 600(ActivityThread.java:140)

  9月3日至一十二日:46:13.155:E / AndroidRuntime(1547):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1227)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.os.Handler.dispatchMessage(Handler.java:99)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.os.Looper.loop(Looper.java:137)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.ActivityThread.main(ActivityThread.java:4898)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在java.lang.reflect.Method.invokeNative(本机方法)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在java.lang.reflect.Method.invoke(Method.java:511)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在dalvik.system.NativeStart.main(本机方法)9月3日至12日:46:13.155:E / AndroidRuntime(1547):android.view.InflateException:二进制XML文件行#2:错误充气类片段产生的原因9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.view.LayoutInflater.inflate(LayoutInflater.java:466)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Activity.setContentView(Activity.java:1924)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在com.android.maptest.MainActivity.onCreate(MainActivity.java:11)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Activity.performCreate(Activity.java:5206)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)9月3日至12日:46:13.155:E / AndroidRuntime(1547):11 ...更多9月3日至12日:46:13.155:E / AndroidRuntime(1547):android.app.Fragment $ InstantiationException:产生的原因无法实例片段com.google.android.gms.maps.MapFragment:确保类名称存在,是公众,并且有一个空的构造是公9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Fragment.instantiate(Fragment.java:584)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Fragment.instantiate(Fragment.java:552)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Activity.onCreateView(Activity.java:4849)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)9月3日至12日:46:13.155:E / AndroidRuntime(1547):20 ...更多9月3日至12日:46:13.155:E / AndroidRuntime(1547):抛出java.lang.ClassNotFoundException:产生的原因com.google.android.gms.maps.MapFragment9月3日至12日:46:13.155:E / AndroidRuntime(1547):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)9月3日至12日:46:13.155:E / AndroidRuntime(1547):在android.app.Fragment.instantiate(Fragment.java:574)9月3日至12日:46:13.155:E / AndroidRuntime(1547):23 ...更多9月3日至12日:51:21.560:I /流程(1547):发送信号。 PID:1547 SIG:9


解决方案

看起来你没有添加谷歌Play服务库到您的项目。

它位于 {Android SDK中} \\演员\\谷歌\\ google_play_services

添加它作为Android的库项目到Eclipse,然后将其添加到项目中。

I have made an app that uses Google Android Maps API V2 and I have followed every step in the guide provided by Google but it doesn't work unfortunely and it crashes every time I try to start it up. So I'm wondering what is the problem?

MainActivity.java

package com.android.maptest;

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);
    }
}

activity_main.xml

<?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"/>

Maptest Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.maptest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="16" />
    <permission
        android:name="com.android.maptest.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="com.android.maptest.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" 
        android:debuggable="true" >
        <activity
            android:name="com.android.maptest.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="api_key" />
    </application>

</manifest>

Logcat

03-12 09:46:13.150: D/AndroidRuntime(1547): Shutting down VM

03-12 09:46:13.150: W/dalvikvm(1547): threadid=1: thread exiting with uncaught exception (group=0x410e22a0)

03-12 09:46:13.155: E/AndroidRuntime(1547): FATAL EXCEPTION: main

03-12 09:46:13.155: E/AndroidRuntime(1547): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.maptest/com.android.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at 

android.app.ActivityThread.access$600(ActivityThread.java:140)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.os.Handler.dispatchMessage(Handler.java:99)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.os.Looper.loop(Looper.java:137)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.ActivityThread.main(ActivityThread.java:4898)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at java.lang.reflect.Method.invokeNative(Native Method)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at java.lang.reflect.Method.invoke(Method.java:511)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at dalvik.system.NativeStart.main(Native Method)

03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Activity.setContentView(Activity.java:1924)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at com.android.maptest.MainActivity.onCreate(MainActivity.java:11)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Activity.performCreate(Activity.java:5206)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)

03-12 09:46:13.155: E/AndroidRuntime(1547):     ... 11 more

03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Fragment.instantiate(Fragment.java:584)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Fragment.instantiate(Fragment.java:552)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Activity.onCreateView(Activity.java:4849)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

03-12 09:46:13.155: E/AndroidRuntime(1547):     ... 20 more

03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment

03-12 09:46:13.155: E/AndroidRuntime(1547):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

03-12 09:46:13.155: E/AndroidRuntime(1547):     at android.app.Fragment.instantiate(Fragment.java:574)

03-12 09:46:13.155: E/AndroidRuntime(1547):     ... 23 more

03-12 09:51:21.560: I/Process(1547): Sending signal. PID: 1547 SIG: 9

解决方案

Looks like you didn't add the Google Play Services library to your project.

It's located at {Android SDK}\extras\google\google_play_services

Add it as Android Library Project to Eclipse and then add it to your project.

这篇关于Android地图应用V2崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆