谷歌MAPS ..不幸的是该计划已经停止

时间:2015-07-01 06:50:42

标签: android google-maps

。我试图在Android应用程序中制作一个简单的谷歌地图程序..但当我启动我的应用程序..不幸停止错误来了.. 请帮助我

这是MainActivity.java

 package com.example.mymaps;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MainActivity extends Activity {

        private GoogleMap mMap;

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

            mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
            Marker ciu = mMap.addMarker(new MarkerOptions()
                                      .position(CIU).title("My Office"));
        }

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

    }

activity_main.xml中

<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"    
android:paddingBottom="@dimen/activity_vertical_margin"    
android:paddingLeft="@dimen/activity_horizontal_margin"    
android:paddingRight="@dimen/activity_horizontal_margin"    
android:paddingTop="@dimen/activity_vertical_margin"    
tools:context=".MainActivity" >
<TextView        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="@string/hello_world" />
<fragment
        android:id="@+id/map"     
        android:layout_width="match_parent"        
        android:layout_height="match_parent"        
class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>

的Manifest.xml

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />
    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
    <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="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission
        android:name="android.permission.INTERNET"/>
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <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="AIzaSyA0MunNdPVAGdely1AS5HsJYhNkszVclFc"/>
        <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>

LogCat:

07-01 12:16:21.804: E/AndroidRuntime(1867): FATAL EXCEPTION: main
07-01 12:16:21.804: E/AndroidRuntime(1867): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.Activity.onCreateView(Activity.java:4663)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.Activity.setContentView(Activity.java:1867)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.example.mymaps.MainActivity.onCreate(MainActivity.java:19)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.Activity.performCreate(Activity.java:5008)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.os.Looper.loop(Looper.java:137)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at java.lang.reflect.Method.invokeNative(Native Method)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at java.lang.reflect.Method.invoke(Method.java:511)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-01 12:16:21.804: E/AndroidRuntime(1867):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

尝试添加

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

在清单中的应用程序代码下。

然后可能有两件事:

1)在AndroidManifest.xml类中定义所有Activity类。

2)使用“Google API”而不是“Android 2.x”编译您的Android项目,如果您只使用Google API进行编译,那么它将添加Google Maps类。

是否在模拟器中安装了Google地图?

尝试更改此内容:

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

对此:

<permission
    android:name="YOUR.PACKAGE.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"></permission>
<uses-permission
    android:name="YOUR.PACKAGE.permission.MAPS_RECEIVE"/>

我认为你.PACKAGE是com.example.mymaps