这是我的onCreate()方法..以前用过两条评论的线来启动地图并且工作正常。后来我发现谷歌不再使用LocationClient而他们使用GoogleAPIClient而不是。所以我改变了它。 / p>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button send = (Button) findViewById(R.id.button2);
if(initMap())
{
//mLocationClient = new LocationClient(this,this,this);
//mLocationClient.connect();
mGoogleApiClient =new GoogleApiClient.Builder(MainActivity.this)
.addApi(LocationServices.API)
.addConnectionCallbacks(MainActivity.this)
.addOnConnectionFailedListener(MainActivity.this)
.build();
}
else
{
Toast.makeText(this,"Map Not Available!",Toast.LENGTH_SHORT).show();
}
}
这是initMap方法
private boolean initMap(){
if(mMap==null)
{
//making Reference to Map Object
SupportMapFragment mapFrag = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mMap=mapFrag.getMap();
}
return(mMap!=null);
}
这是logcat报告。
12-20 15:45:47.195: E/AndroidRuntime(1457): FATAL EXCEPTION: main
12-20 15:45:47.195: E/AndroidRuntime(1457): Process: com.example.mapsproject, PID: 1457
12-20 15:45:47.195: E/AndroidRuntime(1457): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable;
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2158)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.Activity.setContentView(Activity.java:2144)
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.example.mapsproject.MainActivity.onCreate(MainActivity.java:71)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.Activity.performCreate(Activity.java:5933)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.os.Handler.dispatchMessage(Handler.java:102)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.os.Looper.loop(Looper.java:135)
12-20 15:45:47.195: E/AndroidRuntime(1457): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.reflect.Method.invoke(Native Method)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.reflect.Method.invoke(Method.java:372)
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-20 15:45:47.195: E/AndroidRuntime(1457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-20 15:45:47.195: E/AndroidRuntime(1457): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.mapsproject-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
12-20 15:45:47.195: E/AndroidRuntime(1457): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
12-20 15:45:47.195: E/AndroidRuntime(1457): ... 25 more
12-20 15:45:47.195: E/AndroidRuntime(1457): Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.R$styleable
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.Class.classForName(Native Method)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
12-20 15:45:47.195: E/AndroidRuntime(1457): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
12-20 15:45:47.195: E/AndroidRuntime(1457): ... 26 more
12-20 15:45:47.195: E/AndroidRuntime(1457): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
12-20 15:45:51.501: I/Process(1457): Sending signal. PID: 1457 SIG: 9
答案 0 :(得分:1)
以下是您的活动存在的问题,但Eclipse没有在APK中包含支持包... 如果您在堆栈跟踪中查看错误,您会发现问题的根源:
Didn't find class "com.google.android.gms.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.mapsproject-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
所以你可以解压缩apk,取消它,你会看到没有包含兼容性包类。
要解决此问题
使用Eclipse
使用Android Studio
升级到Android Stuido 0.8.2后,我遇到了这个问题。我尝试了很多东西,包括
在重新导入整个项目之前,没有任何工作。
File -> Close Project -> Import Project... -> Choose the same project -> OK
希望这个帮助,如果没有请在下面评论。 :)