0

I want to add an map to a Fragment (err, FragmentActivity?). The java files give no errors, but rather a runtime error appears in the XML file line 65.

here is my code and the error (in the XML, xml attached as well). ....

static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                       Bundle savedInstanceState) {

  View v = inflater.inflate(R.layout.activity_map_, null, false);

  map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment2)).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)));

      map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

      // Zoom in, animating the camera.
      map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
  return v;
}   ...

There is no error there.

12-11 16:19:53.590: D/AndroidRuntime(12278): Shutting down VM
12-11 16:19:53.590: W/dalvikvm(12278): threadid=1: thread exiting with uncaught exception (group=0x4141c930)
12-11 16:19:53.600: E/AndroidRuntime(12278): FATAL EXCEPTION: main
12-11 16:19:53.600: E/AndroidRuntime(12278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.soconnection/com.example.soconnection.FullscreenActivity}: android.view.InflateException: Binary XML file line #65: Error inflating class fragment
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.os.Looper.loop(Looper.java:137)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread.main(ActivityThread.java:5039)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at java.lang.reflect.Method.invokeNative(Native Method)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at java.lang.reflect.Method.invoke(Method.java:511)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at dalvik.system.NativeStart.main(Native Method)
12-11 16:19:53.600: E/AndroidRuntime(12278): Caused by: android.view.InflateException: Binary XML file line #65: Error inflating class fragment
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Activity.setContentView(Activity.java:1881)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at com.example.soconnection.FullscreenActivity.onCreate(FullscreenActivity.java:23)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Activity.performCreate(Activity.java:5104)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-11 16:19:53.600: E/AndroidRuntime(12278):    ... 11 more
12-11 16:19:53.600: E/AndroidRuntime(12278): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportsMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Fragment.instantiate(Fragment.java:592)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Fragment.instantiate(Fragment.java:560)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Activity.onCreateView(Activity.java:4709)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-11 16:19:53.600: E/AndroidRuntime(12278):    ... 25 more
12-11 16:19:53.600: E/AndroidRuntime(12278): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportsMapFragment" on path: /data/app/com.example.soconnection-1.apk
12-11 16:19:53.600: E/AndroidRuntime(12278):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 16:19:53.600: E/AndroidRuntime(12278):    at android.app.Fragment.instantiate(Fragment.java:582)
12-11 16:19:53.600: E/AndroidRuntime(12278):    ... 28 more

And the XML line in question:

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
             65       <fragment THIS IS THE LINE. 
                        android:id="@+id/fragment2"
                        android:name="com.example.soconnection.MapActivity2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" 
                        class ="com.google.android.gms.maps.SupportsMapFragment"/>
            </LinearLayout>

How do I fix this. Unless I overlooked something I have already changed everything to getSUpportFragment etc.

Faraz Masroor
  • 201
  • 2
  • 14

1 Answers1

0
java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportsMapFragment"

Are you using Android Studio? You might need to do a full rebuild. Build --> Rebuild Project

Damian
  • 8,062
  • 4
  • 42
  • 43
  • Sounds like it could be the way you setup googleplayservices. Hopefully you added it as a library project and didn't just drop the jar in your libs directory? Maybe this will help you further http://stackoverflow.com/questions/16572020/error-java-lang-classnotfoundexception-com-google-android-gms-maps-mapfragment – Damian Dec 12 '13 at 10:51