当前位置: 首页 > 知识库问答 >
问题:

java.lang.NoClassDefFoundError:com.google.android.gms.R$在android样式

罗建弼
2023-03-14

我尝试了在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>

我在清单中添加了API密钥。xml,

<?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服务。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

在属性中--

请任何人帮帮我。我是否遗漏了任何参考资料?

共有3个答案

高和通
2023-03-14

当您导入google-play-services_lib时,选中“将项目复制到工作区”。它对我有用!

顾昌翰
2023-03-14

检查google-play-services_lib项目的AndroidManifest.xml文件。应该是:

package="com.google.android.gms"
水铭晨
2023-03-14

请参阅此处的答案:
Google Maps Android API v2-示例代码崩溃
虽然问题列出了不同的异常,但答案特别提到了您的确切问题。

具体来说,将google-play-services\u lib作为项目导入非常重要:
选择文件

  • 导入“google-play-services\u lib”项目的实际源代码,并将其链接为
 类似资料:
  • 我正在使用Google GCM服务开发一个应用程序,它似乎在Launch的所有Lollipop前设备上都崩溃了...我遵循了谷歌教程...以及它在Lollipop和Marshmallow上的工作 以下是我的项目级依赖项 我的应用程序级gradle文件中有此项 还有这个 我还设置了android清单。。以及相应的服务类别,并在Marshmallow设备上接收GCM。 我有这个错误。

  • 我使用以下样式,通常使用ButtonBlue。在菜单上,样式应改为ButtonBlue。大号的款式是这样的: 有没有办法将样式更改为多个按钮?因为我有31个按钮,如果每个按钮都需要手动更改,那就太多了 提前谢谢 编辑:我在活动中应用了按钮蓝色样式。xml 但我的问题是,我不知道如何在Java代码中通过按钮应用新样式

  • Boilerpipe是一个基本上从网页中提取主要内容的库。对于新闻网站来说,提取内容尤其困难,因为不同网站的格式不同。所以我试着整合样板管库-https://code.google.com/p/boilerpipe/wiki/QuickStart 根据安装指南,我已经将以下内容添加到我的Java类路径-boilerpipe版本中。jar,nekohtml-1.9.13。jar和xerces-2.9

  • 我想设计一个寻找栏,看起来像下图中的那个。 通过使用默认搜索栏,我将得到这样的东西: 所以我只需要改变颜色。我不需要额外的款式。有没有什么直接的方法可以做到这一点,或者我应该建立我的自定义绘图。? 我试图建立自定义的一个,但我不能得到确切的一个如上所示。使用自定义drawable后,我得到的结果如下所示: 如果我需要建立一个自定义的,那么请建议如何减少进度线的宽度和形状。 我的自定义实现: bac

  • 问题内容: 问题: 在哪里可以找到带有十六进制颜色代码的默认样式xml? 我在寻找’buttonStyle’样式,其他默认样式会影响诸如TextViews,Buttons等方面(如果您不更改方面的样式) 我抬头望去,但实际上没有找到想要的东西。 希望我的问题清楚。 由于信誉低,我无法回答这个问题。这是答案 回答 稍作谷歌搜索,我发现’buttonStyle’实际上是’Widget.Button’-