java.lang.noclassdeffounderror: com.google.android.gms.R$styleable 没有任何帮助
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16305685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.noclassdeffounderror: com.google.android.gms.R$styleable nothing helped me
提问by brabertaser19
I have such activityclass code:
我有这样的活动类代码:
package com.pavel.exchanger;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
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.support.v4.app.Fragment;
public class SearchExchangerActivity extends FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_exchanger);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.search_exchanger, menu);
return true;
}
}
and such layout:
和这样的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchExchangerActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
and such manifest:
和这样的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pavel.exchanger"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.pavel.exchanger.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.pavel.exchanger.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.pavel.exchanger.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>
<activity
android:name="com.pavel.exchanger.ExchangerListActivity"
android:label="@string/title_activity_exchanger_list" >
</activity>
<activity
android:name="com.pavel.exchanger.BankExchangersListActivity"
android:label="@string/title_activity_bank_exchangers_list" >
</activity>
<activity
android:name="com.pavel.exchanger.NbrbActivity"
android:label="@string/title_activity_nbrb" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.***"
android:value="****" />
<activity
android:name="com.pavel.exchanger.SearchExchangerActivity"
android:label="@string/title_activity_search_exchanger" >
</activity>
</application>
</manifest>
but when i run my activity i get:
但是当我运行我的活动时,我得到:
04-30 17:25:35.926: E/AndroidRuntime(400): FATAL EXCEPTION: main
04-30 17:25:35.926: E/AndroidRuntime(400): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-30 17:25:35.926: E/AndroidRuntime(400): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-30 17:25:35.926: E/AndroidRuntime(400): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-30 17:25:35.926: E/AndroidRuntime(400): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.Activity.setContentView(Activity.java:1657)
04-30 17:25:35.926: E/AndroidRuntime(400): at com.pavel.exchanger.SearchExchangerActivity.onCreate(SearchExchangerActivity.java:26)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.ActivityThread.access00(ActivityThread.java:117)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.os.Looper.loop(Looper.java:123)
04-30 17:25:35.926: E/AndroidRuntime(400): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-30 17:25:35.926: E/AndroidRuntime(400): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 17:25:35.926: E/AndroidRuntime(400): at java.lang.reflect.Method.invoke(Method.java:507)
04-30 17:25:35.926: E/AndroidRuntime(400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-30 17:25:35.926: E/AndroidRuntime(400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-30 17:25:35.926: E/AndroidRuntime(400): at dalvik.system.NativeStart.main(Native Method)
i try to clean project, i added lib and project, i try to google and do some advices.... but nothing helped me(
我尝试清理项目,我添加了 lib 和项目,我尝试谷歌并做一些建议......但没有任何帮助我(
What i'm doing wrong?
我在做什么错?
Note: i must run it on android 2.3.3...
注意:我必须在 android 2.3.3 上运行它...
How to solve this error?
如何解决这个错误?
回答by CommonsWare
If I had to guess, when you "added lib and project", you added the JAR, not the Android library project. The Play Services SDK is an Android library project that happens to contain a JAR.
如果我不得不猜测,当您“添加 lib 和项目”时,您添加的是 JAR,而不是 Android 库项目。Play 服务 SDK 是一个 Android 库项目,它恰好包含一个 JAR。
The Play Services SDK documentationhas the basic steps. Assuming that you are using Eclipse, you need to import the Play Services SDK Android library project into your workspace, then reference that library project from your app (Project > Properties > Android). Also, undo whatever you did originally to attempt to use the Play Services SDK, as that may interfere with the revised setup.
该播放服务SDK文档具有的基本步骤。假设您使用的是 Eclipse,您需要将 Play Services SDK Android 库项目导入您的工作区,然后从您的应用程序中引用该库项目(项目 > 属性 > Android)。此外,撤消您最初尝试使用 Play 服务 SDK 所做的任何操作,因为这可能会干扰修改后的设置。