Android谷歌地图的演示应用程序 - 不幸停止了

时间:2014-04-18 16:32:52

标签: android google-maps

我想将谷歌地图部署到我的Android应用程序中。我按照我在这里找到的一步一步的程序。但是当我运行应用程序时。我得到了“不幸的是你的应用程序已经停止了错误。我按照该文档中的每一步。请告诉我错误。

这是我的logcat的输出

04-18 12:15:30.416: I/Process(1423): Sending signal. PID: 1423 SIG: 9
04-18 12:15:31.676: W/dalvikvm(1443): VFY: unable to resolve static field 2529 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-18 12:15:31.676: D/dalvikvm(1443): VFY: replacing opcode 0x62 at 0x000e
04-18 12:15:31.686: D/AndroidRuntime(1443): Shutting down VM
04-18 12:15:31.686: W/dalvikvm(1443): threadid=1: thread exiting with uncaught exception (group=0xb1a6cba8)
04-18 12:15:31.726: E/AndroidRuntime(1443): FATAL EXCEPTION: main
04-18 12:15:31.726: E/AndroidRuntime(1443): Process: tarun.ksr.mymap, PID: 1443
04-18 12:15:31.726: E/AndroidRuntime(1443): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-18 12:15:31.726: E/AndroidRuntime(1443):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.Activity.onCreateView(Activity.java:4785)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.Activity.setContentView(Activity.java:1929)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at tarun.ksr.mymap.MainActivity.onCreate(MainActivity.java:20)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.Activity.performCreate(Activity.java:5231)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.os.Looper.loop(Looper.java:136)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at java.lang.reflect.Method.invokeNative(Native Method)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at java.lang.reflect.Method.invoke(Method.java:515)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-18 12:15:31.726: E/AndroidRuntime(1443):     at dalvik.system.NativeStart.main(Native Method)
04-18 12:15:34.846: I/Process(1443): Sending signal. PID: 1443 SIG: 9

这是我的MainActivity.java

package tarun.ksr.mymap;

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

}

MANIFEST:

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

<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="AIzaSyCfVTb5mW1c-q8RdBtX7NJJ0S1KXgkHUP0"/>

    <activity
        android:name="tarun.ksr.mymap.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>

1 个答案:

答案 0 :(得分:0)

将此添加到清单 -

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

同时检查Google Play Services SDK是否配置正确。 https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2