gpt4 book ai didi

google-maps-android-api-2 - java.lang.noclassdeffounderror : com. google.android.gms.R$styleable

转载 作者:行者123 更新时间:2023-12-03 05:55:23 26 4
gpt4 key购买 nike

我正在使用谷歌地图创建一个Android应用程序。这是代码:

MapFragActivity.java

 import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MapFragActivity extends FragmentActivity {

private GoogleMap map;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_frag);

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
}
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.him.mapfrag_rnd"
android:versionCode="1"
android:versionName="1.0" >

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


<permission
android:name="com.him.mapfrag_rnd.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-permission android:name="com.him.mapfrag_rnd.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<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=".MapFragActivity"
android:label="@string/title_activity_map_frag" >
<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>

activity_map_frag.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

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

</RelativeLayout>

当我尝试此代码时,出现错误,这是日志:

01-17 10:01:17.685: E/AndroidRuntime(8923): FATAL EXCEPTION: main
01-17 10:01:17.685: E/AndroidRuntime(8923): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.Activity.setContentView(Activity.java:1835)
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.him.mapfrag_rnd.MapFragActivity.onCreate(MapFragActivity.java:16)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.Activity.performCreate(Activity.java:4470)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.os.Looper.loop(Looper.java:137)
01-17 10:01:17.685: E/AndroidRuntime(8923): at android.app.ActivityThread.main(ActivityThread.java:4511)
01-17 10:01:17.685: E/AndroidRuntime(8923): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 10:01:17.685: E/AndroidRuntime(8923): at java.lang.reflect.Method.invoke(Method.java:511)
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:986)
01-17 10:01:17.685: E/AndroidRuntime(8923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
01-17 10:01:17.685: E/AndroidRuntime(8923): at dalvik.system.NativeStart.main(Native Method)

当我在 MapFragActivity.java 中进行一些更改时,就会显示 map 。以下是更改:

package com.him.mapfrag_rnd;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.SupportMapFragment;

public class MapFragActivity extends FragmentActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_map_frag);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
}
}

我所做的更改被注释为 setContentView。我已遵循所有必需的步骤,但仍然出现错误。如果取消注释 setContentView() 然后我再次收到错误。

请帮忙!!!

最佳答案

如果您使用的是 Intellij Idea,

  1. 从项目面板中选择您的项目
  2. 按 F4 打开项目结构窗口
  3. 从左侧面板中选择模块,然后点击 + 按钮,然后选择“导入模块”并导航至“ANDROID-SDK”/extras/google/google_play_services/libproject/google-play-services_lib。通过执行此操作,该项目将与您的项目一起添加到模块中
  4. 选择您的项目,然后从右侧面板中选择“依赖项”(它是一个选项卡)。点击“+”按钮,然后点击“3 Module dependency...”并选择“google-play-services_lib”。
  5. 再次点击“+”按钮,然后点击“1 jars ordirectories...”,导航到上述路径中的“/libs”文件夹,然后选择“google-play-services.jar”。
  6. 单击“确定”并关闭项目结构窗口。

注意:确保您尚未将“google-play-services_lib”项目添加为“库”(模块下的左侧面板)中的库。如果有,您可以转到“”并将其删除。Google Play 库不应出现在库中

注 2:如果您希望将整个 google-play-services_lib 目录纳入版本控制或类似项目,您可以将其复制到您自己的项目中。

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

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