Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图api v2_Android_Noclassdeffounderror_Avd_Google Maps Android Api 2 - Fatal编程技术网

Android 谷歌地图api v2

Android 谷歌地图api v2,android,noclassdeffounderror,avd,google-maps-android-api-2,Android,Noclassdeffounderror,Avd,Google Maps Android Api 2,我正在尝试从运行Google maps API v2的一个基本示例,但它不断出现错误: 02-10 14:51:38.292: E/AndroidRuntime(898): FATAL EXCEPTION: main 02-10 14:51:38.292: E/AndroidRuntime(898): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 02-10 14:51:38.292: E/AndroidRu

我正在尝试从运行Google maps API v2的一个基本示例,但它不断出现错误:

02-10 14:51:38.292: E/AndroidRuntime(898): FATAL EXCEPTION: main
02-10 14:51:38.292: E/AndroidRuntime(898): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.Activity.onCreateView(Activity.java:4716)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.Activity.setContentView(Activity.java:1881)
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.vogella.android.locationapi.maps.MainActivity.onCreate(MainActivity.java:23)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.Activity.performCreate(Activity.java:5104)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.os.Looper.loop(Looper.java:137)
02-10 14:51:38.292: E/AndroidRuntime(898):  at android.app.ActivityThread.main(ActivityThread.java:5039)
02-10 14:51:38.292: E/AndroidRuntime(898):  at java.lang.reflect.Method.invokeNative(Native Method)
02-10 14:51:38.292: E/AndroidRuntime(898):  at java.lang.reflect.Method.invoke(Method.java:511)
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-10 14:51:38.292: E/AndroidRuntime(898):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-10 14:51:38.292: E/AndroidRuntime(898):  at dalvik.system.NativeStart.main(Native Method)
我的代码

舱单:

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

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

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="com.example.mapdemo.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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.vogella.android.locationapi.maps.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>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="{tried both browser api key and android api keys here}" />
    </application>

</manifest>

当然,如果在目标为Google API 17的AVD上运行它,它会立即崩溃。

我注意到您没有为Google Play服务添加保护,Google Maps V2 API要求运行它

问题可能是由于AVD不支持Google Play服务。尝试在设备上运行

也许这些能帮上忙


您应该将片段活动扩展到活动

在活动中使用此选项: map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap()

片段标记中的xml中写下:


class=“com.google.android.gms.maps.SupportMapFragment

谢谢,我不确定我是否了解这些保护是什么。除了检查AVD上的播放服务可用性并尝试在真实设备上运行外,还有什么我应该做的吗?保护措施是测试设备上是否有Google play服务,因为默认情况下没有安装。-另外,我相信您已经下载了,但请仔细检查您是否已从SDK管理器下载了Google play services API
<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.MapFragment" />

</RelativeLayout>
package com.vogella.android.locationapi.maps;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
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 {
    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG).title("Hamburg"));
    Marker kiel =
        map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
    }

}