0

我试图在 Android 中测试 Google Maps API。但是在编译过程中我收到了这个错误:

04-03 21:40:30.209: E/AndroidRuntime(14016): FATAL EXCEPTION: main
04-03 21:40:30.209: E/AndroidRuntime(14016): java.lang.ExceptionInInitializerError
04-03 21:40:30.209: E/AndroidRuntime(14016):    at java.lang.Class.newInstanceImpl(Native Method)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at java.lang.Class.newInstance(Class.java:1319)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.ActivityThread.access$600(ActivityThread.java:132)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.os.Looper.loop(Looper.java:137)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at android.app.ActivityThread.main(ActivityThread.java:4575)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at java.lang.reflect.Method.invokeNative(Native Method)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at java.lang.reflect.Method.invoke(Method.java:511)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
04-03 21:40:30.209: E/AndroidRuntime(14016):    at dalvik.system.NativeStart.main(Native Method)
04-03 21:40:30.209: E/AndroidRuntime(14016): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng
04-03 21:40:30.209: E/AndroidRuntime(14016):    at com.omerjerk.sticktracker.MainActivity.<clinit>(MainActivity.java:16)
04-03 21:40:30.209: E/AndroidRuntime(14016):    ... 15 more

我在 StackOverflow 上进行了搜索,但我认为我的代码中可能没有任何问题。我是否需要针对 Google API 或 SDK 进行编译?

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />
<permission
    android:name="com.omerjerk.sticktracker.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.omerjerk.sticktracker.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
 Google Maps Android API v2, but are recommended. -->
<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" >
    <uses-library android:required="true" android:name="com.google.android.maps" />
    <activity
        android:name="com.omerjerk.sticktracker.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="AIzaSyDKwhbavlZaQXehStVJpg-ho_6mwkUCLYo" />

</application>

4

1 回答 1

1

你的问题是这样的:

Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng

Latlng基本找不到类包。Latlnggoogle-play-services图书馆的一部分,这意味着你对谷歌的包有某种引用问题。

检查我写的本指南的第 1-3 步,将 Google 地图添加到您的应用程序以供google-play-service图书馆参考:

谷歌地图 API V2

于 2013-04-03T22:54:07.513 回答