找不到类'com.google.android,gms.maps.supportfragment

时间:2014-11-14 17:21:33

标签: android google-maps

我正在使用谷歌地图,并且已经关注this教程。我已经在下面编写了我的代码。我在logcat中收到了无法找到类&com; google.android,gms的错误。 maps.supportfragment.Plz提前帮助我。谢谢。

package com.google.android.gms;


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

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

public class MainActivity extends FragmentActivity {

  SupportMapFragment mapFragment;
  GoogleMap map;
  final String TAG = "myLogs";

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

    mapFragment = (SupportMapFragment) getSupportFragmentManager()
        .findFragmentById(R.id.map);
    map = mapFragment.getMap();
    if (map == null) {
      finish();
      return;
    }
    init();
  }

  private void init() {
    }


  public void onClickTest(View view) {
    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
  }
}

这是Logcat:

11-14 12:24:21.506: I/dalvikvm(1383): Could not find method com.google.android.gms.maps.GoogleMap.setMapType, referenced from method com.google.android.gms.MainActivity.onClickTest
11-14 12:24:21.536: W/dalvikvm(1383): VFY: unable to resolve virtual method 4792: Lcom/google/android/gms/maps/GoogleMap;.setMapType (I)V
11-14 12:24:21.536: D/dalvikvm(1383): VFY: replacing opcode 0x6e at 0x0003
11-14 12:24:21.567: E/dalvikvm(1383): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.google.android.gms.MainActivity.onCreate
11-14 12:24:21.576: W/dalvikvm(1383): VFY: unable to resolve check-cast 683 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/google/android/gms/MainActivity;
11-14 12:24:21.576: D/dalvikvm(1383): VFY: replacing opcode 0x1f at 0x0013
11-14 12:24:22.016: D/AndroidRuntime(1383): Shutting down VM
11-14 12:24:22.016: W/dalvikvm(1383): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
11-14 12:24:22.046: E/AndroidRuntime(1383): FATAL EXCEPTION: main
11-14 12:24:22.046: E/AndroidRuntime(1383): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms/com.google.android.gms.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.os.Looper.loop(Looper.java:137)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread.main(ActivityThread.java:5103)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at java.lang.reflect.Method.invokeNative(Native Method)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at java.lang.reflect.Method.invoke(Method.java:525)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at dalvik.system.NativeStart.main(Native Method)
11-14 12:24:22.046: E/AndroidRuntime(1383): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.Activity.setContentView(Activity.java:1895)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at com.google.android.gms.MainActivity.onCreate(MainActivity.java:20)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.Activity.performCreate(Activity.java:5133)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-14 12:24:22.046: E/AndroidRuntime(1383):     ... 11 more
11-14 12:24:22.046: E/AndroidRuntime(1383): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
11-14 12:24:22.046: E/AndroidRuntime(1383):     ... 21 more
11-14 12:24:22.046: E/AndroidRuntime(1383): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.google.android.gms-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gms-2, /system/lib]]
11-14 12:24:22.046: E/AndroidRuntime(1383):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-14 12:24:22.046: E/AndroidRuntime(1383):     at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
11-14 12:24:22.046: E/AndroidRuntime(1383):     ... 24 more

这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 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"
 android:orientation="vertical">
<Button
 android:id="@+id/btnTest"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="onClickTest"
 android:text="test">
</Button>
<mapfragment
 android:id="@+id/map"
 android:name="com.google.android.gms.maps.SupportMapFragment"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
</mapfragment>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您还需要支持库,而不仅仅是播放服务库。 打开sdk管理器并下载它,然后将其包含在您的项目中。

你的mapfragment在xml中应该是这样的:

<fragment
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>