gpt4 book ai didi

java.lang.NoClassDefFoundError : com. google.android.gms.maps.model.LatLng 即使在将 google-play-services_lib 添加为库项目之后

转载 作者:行者123 更新时间:2023-11-30 02:03:56 24 4
gpt4 key购买 nike

我正在尝试在 android 中实现 Google map ,但每当我在模拟器上运行该应用程序时,它都会给我以下错误:

06-25 02:21:52.890: E/AndroidRuntime(931): FATAL EXCEPTION: main
06-25 02:21:52.890: E/AndroidRuntime(931): java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng
06-25 02:21:52.890: E/AndroidRuntime(931): at com.example.directions.MainActivity.<clinit>(MainActivity.java:14)
06-25 02:21:52.890: E/AndroidRuntime(931): at java.lang.Class.newInstanceImpl(Native Method)
06-25 02:21:52.890: E/AndroidRuntime(931): at java.lang.Class.newInstance(Class.java:1130)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.os.Looper.loop(Looper.java:137)
06-25 02:21:52.890: E/AndroidRuntime(931): at android.app.ActivityThread.main(ActivityThread.java:5103)
06-25 02:21:52.890: E/AndroidRuntime(931): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 02:21:52.890: E/AndroidRuntime(931): at java.lang.reflect.Method.invoke(Method.java:525)
06-25 02:21:52.890: E/AndroidRuntime(931): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
06-25 02:21:52.890: E/AndroidRuntime(931): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-25 02:21:52.890: E/AndroidRuntime(931): at dalvik.system.NativeStart.main(Native Method)

以下是MainActivity.java:

package com.example.directions;
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;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
public class MainActivity extends Activity {
static final LatLng position = new LatLng(21, 57);
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
Marker pos = googleMap.addMarker(new MarkerOptions().position(
position).title("My Position"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

这是 activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</RelativeLayout>

我一直在寻找解决方案。我已经将 Google Play 服务添加为库:File->Import->Existing Android Code into workspace ->Selecting the google play services lib -> Copy projects into workspace

我还在 properties -> Library -> Add-> Google play services lib 中添加了该项目。

请帮助..提前致谢。

最佳答案

在 android list 中包含以下行

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

关于java.lang.NoClassDefFoundError : com. google.android.gms.maps.model.LatLng 即使在将 google-play-services_lib 添加为库项目之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com