谷歌地图 android API V2 崩溃 [英] Google map android API V2 crashed

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

问题描述

我想在我的安卓上加载谷歌地图 API.我尝试了我搜索的所有内容,但它仍然崩溃.这是我的 MainActivity.java

包 com.example.androidmapsv2;导入android.os.Bundle;导入android.support.v4.app.FragmentActivity;导入 com.google.android.gms.common.GooglePlayServicesUtil;导入 com.google.android.gms.maps.GoogleMap;导入 com.google.android.gms.maps.SupportMapFragment;公共类 MainActivity 扩展 FragmentActivity {@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//在操作栏中显示向上按钮.getActionBar().setDisplayHomeAsUpEnabled(true);GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());GoogleMap 地图 = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();}}

这是我的布局 activity_main.xml

<?xml version="1.0" encoding="utf-8"?><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"工具:context=".MainActivity" ><片段android:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment"/></相对布局>

这是我的清单

<?xml version="1.0" encoding="utf-8"?><清单 xmlns:android="http://schemas.android.com/apk/res/android"包="com.example.androidmapsv2"安卓:版本代码=1"android:versionName="1.0" ><使用-sdk安卓:m​​inSdkVersion="11"android:targetSdkVersion="16"/><许可android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"android:protectionLevel="签名" ></许可><使用权限 android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/><使用权限 android:name="android.permission.INTERNET"/><使用权限 android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/><使用权限 android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><使用权限 android:name="android.permission.ACCESS_FINE_LOCATION"/><!-- 需要 OpenGL ES 版本 2 --><用途-特征安卓:glEsVersion="0x00020000"android:required="true"/><应用机器人:allowBackup="真"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><使用库 android:name="com.google.android.maps"/><活动android:name="com.example.androidmapsv2.MainActivity"机器人:标签=aaa"><意图过滤器><action android:name="android.intent.action.MAIN"/><类别 android:name="android.intent.category.LAUNCHER"/></意图过滤器></活动><元数据android:name="com.google.android.maps.v2.API_KEY"android:value="AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ"/></应用程序></清单>

这是我的钥匙

这是包含的库(在更新中解决)

而且我没有真正的 android 设备,所以我在这个教程

这是日志猫

 01-09 18:05:19.184:E/Trace(1366):错误打开跟踪文件:没有这样的文件或目录 (2)01-09 18:05:19.354: W/dalvikvm(1366): 无法解析 Lcom/example/androidmapsv2/MainActivity 的超类;(5)01-09 18:05:19.354: W/dalvikvm(1366): 类 'Lcom/example/androidmapsv2/MainActivity;' 的链接失败的01-09 18:05:19.365: D/AndroidRuntime(1366): 关闭 VM01-09 18:05:19.365: W/dalvikvm(1366): threadid=1: 线程以未捕获的异常退出 (group=0x40a13300)01-09 18:05:19.384:E/AndroidRuntime(1366):致命异常:主要01-09 18:05:19.384: E/AndroidRuntime(1366): java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread.access$600(ActivityThread.java:130)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.os.Handler.dispatchMessage(Handler.java:99)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.os.Looper.loop(Looper.java:137)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread.main(ActivityThread.java:4745)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 java.lang.reflect.Method.invokeNative(Native Method)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 java.lang.reflect.Method.invoke(Method.java:511)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.NativeStart.main(Native Method)01-09 18:05:19.384: E/AndroidRuntime(1366): 原因: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity01-09 18:05:19.384: E/AndroidRuntime(1366): 在 dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 java.lang.ClassLoader.loadClass(ClassLoader.java:501)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 java.lang.ClassLoader.loadClass(ClassLoader.java:461)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.Instrumentation.newActivity(Instrumentation.java:1053)01-09 18:05:19.384: E/AndroidRuntime(1366): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)01-09 18:05:19.384: E/AndroidRuntime(1366): ... 11 更多

更新

我尝试将 google-play-services_lib 复制到工作区,红色标记消失但它又出现了一个错误.它缺少 google-play-services_lib.jar(lib 文件夹名称 + .jar).如何解决当我点击 google-play-services_lib.jar 时,删除按钮不显示(如图).但是我尝试删除所有 Android 依赖项并再次导入其他库.现在它工作了,但仍然崩溃.

我尝试过改变

MainActivity 扩展 Activity

MainActivity 扩展 FragmentActivity

和布局

<?xml version="1.0" encoding="utf-8"?><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"工具:context=".MainActivity" ><片段android:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment"/></相对布局>

它出现另一个错误.帮帮我,现在我没办法解决这个问题

最后,我解决了我的错误.它是由我的日食引起的(我猜).添加库类时,它会自动出现google-play-services_lib.jar",您无需执行任何操作.我重新安装了 Eclipse,一切正常

解决方案

我也遇到过这种问题,第一次用API V2编写地图的时候.

只需尝试使用带有 FragmentActivity 的扩展而不是 Activity

您必须将项目(goolge_play_services)复制到您的工作区,然后将其附加到您的项目中.在上图中它显示了红色的十字,所以选择它并删除,然后再次添加附加库与项目.

I want to load the google map API on my android. I try everything I search but it still crash. this is my MainActivity.java

package com.example.androidmapsv2;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

        GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    }

}

This is my layout activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
        class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>

This is my manifest

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="16" />

    <permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" >
    </permission>

    <uses-permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Require OpenGL ES version 2 -->
    <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" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.example.androidmapsv2.MainActivity"
            android:label="aaa" >
            <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="AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ" />
    </application>

</manifest>

This is the key i've got

This is the libs included (Solved in update)

and i don't have a real android device, so i install it on emulator in this tutorial

This is the logcat

   01-09 18:05:19.184: E/Trace(1366): error opening trace file: No such file or directory (2)
01-09 18:05:19.354: W/dalvikvm(1366): Unable to resolve superclass of Lcom/example/androidmapsv2/MainActivity; (5)
01-09 18:05:19.354: W/dalvikvm(1366): Link of class 'Lcom/example/androidmapsv2/MainActivity;' failed
01-09 18:05:19.365: D/AndroidRuntime(1366): Shutting down VM
01-09 18:05:19.365: W/dalvikvm(1366): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-09 18:05:19.384: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-09 18:05:19.384: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.os.Looper.loop(Looper.java:137)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at dalvik.system.NativeStart.main(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): Caused by: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:05:19.384: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:05:19.384: E/AndroidRuntime(1366):     ... 11 more

UPDATED

i've tried to copy the google-play-services_lib to workspace and red mark disappear but it come another error. It missing the google-play-services_lib.jar (the lib folder name + .jar). how to fix it when i click the google-play-services_lib.jar, the remove button doesn't show up(like picture). However i try remove all Android Dependencies and import the others lib again. now it working, but still crash.

I've tried change

MainActivity extends Activity

To

MainActivity extends FragmentActivity

and the layout

<?xml version="1.0" encoding="utf-8"?>
<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"
        class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>

it appear another error. help me, now i'm out of solution for this

Finally, i solved my error. It caused by my eclipse (i guess). When you add the library class, it automatically appear "google-play-services_lib.jar", you don't have to do anything. I reinstall Eclipse and everything work fine

解决方案

I also faces this kind of the problem,when first time coding for the map with API V2.

Just try using the extends with FragmentActivity instead of the Activity

you have to copy the project(goolge_play_services) into your workspace and then attach it to your project. In above image it show the cross red,so select it and remove and then after once again add attach the library with the project.

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

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