应用程序包括谷歌地图崩溃

时间:2014-09-08 21:47:12

标签: android api google-maps crash

几天后,我尝试使用简单的Google Map(使用Google API V2)创建应用。 我对桌面上的java(win / linux)有一点经验,但这是我进入android世界的第一步。

我的第一次成功,是“点头”灰色谷歌地图 - 我相信因为关键问题而没有加载瓷砖......

经过大量的帖子后线程(也在这里 - 感谢2全部!)我现在有一个APP在手机上崩溃:(但仍然没有地图......

我列出我的代码并请求4帮助 - 我错了什么?

package com.example.mapstests;

import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;

import com.example.mapstests.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;


public class MainActivity extends MapActivity {

//  private GoogleMap mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    private GoogleMap gMap;


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

        try {
            // Loading map
            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }


        MapView mapView = (MapView) findViewById(R.id.map);
        mapView.setBuiltInZoomControls(true);


    }

    @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
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

     @Override
        protected void onResume() {
            super.onResume();
            initilizeMap();
        }


     // Map wird mit Sicherheit geladen, gibts keine soll Fehlermeldung auftauchen 
    private void initilizeMap() {
        if (gMap == null) {
            gMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (gMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
            }
        }
    }

}

在这里我的清单

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


    <!-- Freigaben welche die App zum funktionieren braucht -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.example.mapstestspermission.MAPS_RECEIVE" />
    <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-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


    <!-- OpenGL Unterstützung -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

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


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


    <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.gms.version" 
       android:value="@integer/google_play_services_version" />

        <uses-library android:name="com.google.android.maps"/>

        <activity
            android:name="com.example.mapstests.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
             <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        </activity>


        <!-- Name der App und der Wert des API keys -->
         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="here is my key" />


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


    </application>

</manifest>

和布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:background="#F2F5A9"

    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin_0"
    android:paddingLeft="@dimen/activity_horizontal_margin_0"
    android:paddingRight="@dimen/activity_horizontal_margin_0"
    android:paddingTop="@dimen/activity_vertical_margin_0"
    tools:context=".MainActivity" >

    <fragment        
      android:id="@+id/map"
      android:name="com.google.android.gms.maps.MapFragment"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:background="#0101DF">  

     <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/button" />
     </LinearLayout>

</LinearLayout>

缺少logcat的东西......如何导出这个日志?

0 个答案:

没有答案