gpt4 book ai didi

android - android 中的 java.lang.NoClassDefFoundError : com. google.android.gms.R$styleable

转载 作者:可可西里 更新时间:2023-11-01 19:09:47 27 4
gpt4 key购买 nike

我尝试了一个在 android 中显示 google maps v2 的演示。

java代码是,

package com.example.gpslocator;

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

public class MainActivity extends Activity {

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


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

Xml代码是,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>

我在 manifest.xml 中添加了 API key ,

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

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

<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" />

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

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

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

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.gpslocator.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="MY_API_KEY" />
</application>

</manifest>

当我尝试运行我的应用程序时突然关闭。当我调试时,它向我显示了错误“java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable”。 我将 google-play-services.jar 文件添加到我的应用程序中。

logcat 是,

04-09 05:33:53.677: E/Trace(1053): error opening trace file: No such file or directory (2)
04-09 05:33:53.807: W/ActivityThread(1053): Application com.example.gpslocator is waiting for the debugger on port 8100...
04-09 05:33:53.878: I/System.out(1053): Sending WAIT chunk
04-09 05:33:54.207: I/dalvikvm(1053): Debugger is active
04-09 05:33:54.288: I/System.out(1053): Debugger has connected
04-09 05:33:54.288: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.487: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.697: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.897: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.097: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.297: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.498: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.708: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.907: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:56.167: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:56.367: I/System.out(1053): debugger has settled (1344)
04-09 05:34:06.097: W/dalvikvm(1053): VFY: unable to resolve static field 867 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-09 05:34:06.097: D/dalvikvm(1053): VFY: replacing opcode 0x62 at 0x000e
04-09 05:40:21.278: D/AndroidRuntime(1053): Shutting down VM
04-09 05:40:21.278: W/dalvikvm(1053): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-09 05:40:21.398: E/AndroidRuntime(1053): FATAL EXCEPTION: main
04-09 05:40:21.398: E/AndroidRuntime(1053): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.Activity.onCreateView(Activity.java:4716)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.Activity.setContentView(Activity.java:1881)
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.example.gpslocator.MainActivity.onCreate(MainActivity.java:12)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.Activity.performCreate(Activity.java:5104)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.os.Looper.loop(Looper.java:137)
04-09 05:40:21.398: E/AndroidRuntime(1053): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-09 05:40:21.398: E/AndroidRuntime(1053): at java.lang.reflect.Method.invokeNative(Native Method)
04-09 05:40:21.398: E/AndroidRuntime(1053): at java.lang.reflect.Method.invoke(Method.java:511)
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-09 05:40:21.398: E/AndroidRuntime(1053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-09 05:40:21.398: E/AndroidRuntime(1053): at dalvik.system.NativeStart.main(Native Method)
04-09 05:40:26.487: I/Process(1053): Sending signal. PID: 1053 SIG: 9

在属性-->Android-->

enter image description here

请任何人帮助我。我缺少任何引用吗?

最佳答案

请看这里的答案:
Google Maps Android API v2 - Sample Code crashes
虽然问题列出了不同的异常(exception)情况,但答案特别提到了您的确切问题。

具体来说,将 google-play-services_lib 作为项目 导入很重要:
选择 File > Import > Android > Existing Android Code Into Workspace 并单击 Next。
选择 Browse...,输入 [android-sdk-folder]/extras/google/google_play_services/libproject/google-play-services_lib,然后点击 Finish。
(参见“示例代码”下的 https://developers.google.com/maps/documentation/android/intro)
然后按照链接答案中的说明进行操作:

  • Import the actual source for the "google-play-services_lib" project and link it as an >Android library.
    • Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
    • Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.

关于android - android 中的 java.lang.NoClassDefFoundError : com. google.android.gms.R$styleable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15894143/

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