1

My app is already using the Google Maps Android API v2 and it is working on my Galaxy Mini (Android 2.3.6). When I try to test in on an emulator using Platform 4.0.3, API level 15 and Google APIs, a get the following error:

01-23 14:26:31.581: ERROR/AndroidRuntime(688): FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.remotepark/br.com.remotepark.activities.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    at android.app.ActivityThread.access$600(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
    at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
    at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
    at br.com.remotepark.activities.MainActivity.onCreate(MainActivity.java:51)
    at android.app.Activity.performCreate(Activity.java:4465)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    ... 11 more
    Caused by: java.lang.NullPointerException
    at br.com.remotepark.fragments.MapFragment.initLocation(MapFragment.java:86)
    at br.com.remotepark.fragments.MapFragment.onCreateView(MapFragment.java:62)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:270)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
    ... 22 more

The line that throws the exception is this:

mMap.setInfoWindowAdapter(new MapInfoWindowAdapter(getLayoutInflater(savedInstanceState)));

The MapInfoWindowAdapter constructor is like this:

MapInfoWindowAdapter(LayoutInflater layoutInflater) {
        mLayoutInflater = layoutInflater;

        mWindow = mLayoutInflater.inflate(R.layout.map_info_window, null);
        mContents = mLayoutInflater.inflate(R.layout.map_info_window, null);
    }

And the map_info_window.xml is:

<ImageView
    android:layout_width="40dip"
    android:layout_height="40dip"
    android:src="@drawable/ic_remote_park"
    android:id="@+id/remotepark_logo"
    android:layout_marginLeft="0dip"
    android:layout_marginRight="8dip"
    android:layout_marginTop="16dip"></ImageView>

<LinearLayout
    android:id="@+id/balloon_inner_layout"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_weight="1"
    android:paddingTop="5dip">
    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="0dip">
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textColor="#FFF"
            android:id="@+id/parking_name_info_window"
            android:textSize="7pt"
            android:singleLine="true"
            android:textStyle="bold"
            android:ellipsize="end"/>
    </LinearLayout>
    <RelativeLayout
        android:id="@+id/RelativeLayout2"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_marginTop="2dip">
        <RelativeLayout
            android:id="@+id/frameLayout1"
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content">
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="#FFF"
                android:id="@+id/availability_label_info_window"
                android:text="@string/places_str"
                android:textStyle="bold"/>
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="#FFF"
                android:id="@+id/availability_info_window"
                android:layout_toRightOf="@+id/availability_label_info_window"
                android:layout_marginLeft="5dip" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/RelativeLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentRight="true">

            <TextView
                android:id="@+id/price_label_info_window"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFF"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/price_symbol_info_window"
                android:layout_toRightOf="@+id/price_label_info_window"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/price_symbol_str"
                android:textColor="#FFF"
                android:layout_marginLeft="5dip"/>

            <TextView
                android:id="@+id/price_info_window"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFF"
                android:layout_toRightOf="@+id/price_symbol_info_window"
                android:layout_marginLeft="2dip"/>
        </RelativeLayout>
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/RelativeLayout4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="right"
        android:layout_marginBottom="5dip">

    </RelativeLayout>
</LinearLayout>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/btn_more_info_disabled"
    android:id="@+id/more_info_button"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="8dip"
    android:layout_marginTop="16dip"></ImageView></LinearLayout>

Do you have any idea why its not working?

juliano.net
  • 7,982
  • 13
  • 70
  • 164
  • 1
    mapview does not work in the emulator right out of the box IIRC there are things you need to do to get it to work – tyczj Jan 23 '13 at 14:41

1 Answers1

0

According to Google, Google Play services API's require 'physical development device', so they are not officially supported on the emulators. So, if you are running on an emulator, it is almost certain you are missing the required services. People report getting it to work in emulators, but I have not tried myself. You can view than answers in this post, if you want to look at installing Google Play on an emulator.

You are getting an error when you try to inflate the MapFragment or SupportMapFragment from your xml. It is usually a good idea to check if the device has Google Play services by calling isGooglePlayServicesAvailable(), and make sure it returns ConnectionResult.SUCCESS before proceeding. This allows you to present an error dialog instead of just crashing. Google has even provided an error dialog for some othercodes, you can have them prompted to upgrade/install via getErrorDialog(), like --

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
switch (resultCode) {
   case ConnectionResult.SUCCESS: // proceed
      break;
    case ConnectionResult.SERVICE_MISSING:
    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
    case ConnectionResult.SERVICE_DISABLED:
          Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
          dialog.show();
 }

Do this before calling setContentView.

Community
  • 1
  • 1
iagreen
  • 31,470
  • 8
  • 76
  • 90