簡體   English   中英

Android Google Map V2-“很遺憾,應用已停止”

[英]Android Google Map V2 - “unfortunately App has stopped”

當用戶單擊按鈕時,我正在嘗試在我的Android應用上顯示Google地圖。 當我單擊按鈕時,應用程序停止。代碼中沒有錯誤。 我相信我做對了一切1-我知道了API KEY

2-我將Google_Play_Services_lib.jar添加到依賴文件夾

3添加了額外的支持工具

4-包含權限,清單的我的鑰匙

5-將片段添加到地圖的xml布局文件中

請幫忙,我覺得我已經閱讀並觀看了所有教程,但沒有任何效果!

我的日志:

03-10 20:27:10.057: I/Process(17287): Sending signal. PID: 17287 SIG: 9
03-10 20:27:15.072: D/libEGL(17688): loaded /vendor/lib/egl/libEGL_adreno.so
03-10 20:27:15.072: D/libEGL(17688): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
03-10 20:27:15.082: D/libEGL(17688): loaded /vendor/lib/egl/libGLESv2_adreno.so
03-10 20:27:15.082: I/Adreno-EGL(17688): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build:  (CL4169980)
03-10 20:27:15.082: I/Adreno-EGL(17688): OpenGL ES Shader Compiler Version: 17.01.10.SPL
03-10 20:27:15.082: I/Adreno-EGL(17688): Build Date: 09/26/13 Thu
03-10 20:27:15.082: I/Adreno-EGL(17688): Local Branch: 
03-10 20:27:15.082: I/Adreno-EGL(17688): Remote Branch: 
03-10 20:27:15.082: I/Adreno-EGL(17688): Local Patches: 
03-10 20:27:15.082: I/Adreno-EGL(17688): Reconstruct Branch: 
03-10 20:27:15.122: D/OpenGLRenderer(17688): Enabling debug mode 0
03-10 20:27:16.683: D/AndroidRuntime(17688): Shutting down VM
03-10 20:27:16.683: W/dalvikvm(17688): threadid=1: thread exiting with uncaught exception (group=0x41931898)
03-10 20:27:16.693: E/AndroidRuntime(17688): FATAL EXCEPTION: main
03-10 20:27:16.693: E/AndroidRuntime(17688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newandroid/com.example.newandroid.Mymap}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-10 20:27:16.693: E/AndroidRuntime(17688):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
03-10 20:27:16.693: E/AndroidRuntime(17688):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-10 20:27:16.693: E/AndroidRuntime(17688):    at android.app.ActivityThread.access$700(ActivityThread.java:159)

我的Mymap活動代碼p

ackage com.example.newandroid;

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

public class Mymap extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mymap);
    }
}

我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

表現

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.example.newandroid"
        android:versionCode="1"
        android:versionName="1.0" >

    <permission
            android:name="com.example.newandroid.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />
        <uses-permission android:name="com.example.newandroid.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" />

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

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

            <activity
            android:name="com.example.newandroid.Mymap"
            android:label="@string/title_activity_mymap"
            android:parentActivityName="com.example.newandroid.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.newandroid.MainActivity" />
                </activity>

                 <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAq44a-wWB4W6muJJqZ1DMH-livYscbiyk"/>
        </application>

    </manifest>

這是MainActivity所在的按鈕,單擊該按鈕應啟動Mymap活動。這是Mainactivity代碼

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;


public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
        // TODO Auto-generated method stub
    }
    public void view_map(View view) {
        Intent intent = new Intent(this, Mymap.class);
        startActivity(intent);


        // Do something in response to button
    }
}

您是否嘗試查看此SO帖子? 似乎更改xml以匹配您的類名可以解決大多數問題。

Google Maps V2-錯誤放大類片段

如果您的目標是api級別8和更高級別,則不能使用簡單的Activity ,則需要擴展FragmentActivity

我猜這是您出現充氣問題的原因。

而且您在清單文件中缺少此meta-data部分:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

將其放在您的api鍵meta-data部分旁邊。

我在最近的應用程序開發中確實使用了Android的Google Maps v2 API,甚至無法開始告訴您將地圖顯示在屏幕上需要多長時間。 我最終成功了,我在Github上有一個項目,您可以瀏覽並確保通讀所有重要文件,例如Manifest和res /文件夾;

Google Maps API(Android)v2片段問題

希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM