2

i recieve this error:

android.view.InflateException: Binary XML file line #13: Error inflating class com.google.android.maps.MapView

here is my MapView class

public class MapViewActivity extends BaseFragment {
private TextView mTvTitle;
private View mView;

/*mapview members*/
private MapView mMapView;
private MapController mapController;
private LocationManager locationManager;
private MyLocationOverlay myLocationOverlay;
private static final int DEFAULT_ZOOM = 14;
private GeoUpdateHandler locationListener =  new GeoUpdateHandler();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}


@Override
public void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
}

@Override
public void onPause() {
    super.onPause();
    locationManager.removeUpdates(locationListener);
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
}

@Override
public void onDestroy() {
    super.onDestroy();
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
}

@SuppressWarnings("unchecked")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.map_activity, container, false);
    mTvTitle  = (TextView) mView.findViewById(R.id.tvTitle);
    mTvTitle.setText(getResources().getString(R.string.top_tab_around));

    mMapView = (MapView) mView.findViewById(R.id.mvMapAroundMe);

    BindMap();
    return mView;
}

private void BindMap() {

    mMapView.preLoad();
    mMapView.setBuiltInZoomControls(true);
    mMapView.setSatellite(false);
    mapController = mMapView.getController();
    mapController.setZoom(14); // Zoom 1 is world view

    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

    myLocationOverlay = new MyLocationOverlay(getActivity(), mMapView);
    mMapView.getOverlays().add(myLocationOverlay);

    Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
    List<Overlay> mapOverlays = mMapView.getOverlays();
    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable, getActivity());
    OverlayItem oItem = new OverlayItem(GeopointFactory(33.446886, -86.057426),  "title", "title2");
    itemizedoverlay.addOverlay(oItem);
    mapOverlays.add(itemizedoverlay);
    mapOverlays.add(itemizedoverlay);

    myLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
            animateToPlaceOnMap ( GeopointFactory(33.446886, -86.057426) );
        }
    });
}


public class GeoUpdateHandler implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        mapController.animateTo( GeopointFactory(location.getLatitude(), location.getLongitude()));
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}


private class MyItemizedOverlay extends ItemizedOverlay {
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
    }

    public MyItemizedOverlay(Drawable marker, Context context) {
        super(boundCenterBottom(marker));
        mContext = context;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
        final int tempIndex = index;
        OverlayItem item = mOverlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());

        dialog.setPositiveButton("פרטים",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.show();
        return true;
    }
}

private void animateToPlaceOnMap(final GeoPoint geopoint) {
    mMapView.post(new Runnable() {
        @Override
        public void run() {
            mMapView.invalidate();
            mapController.animateTo(geopoint);
            mapController.setZoom(DEFAULT_ZOOM);
        }
    });
}

private GeoPoint GeopointFactory(double latitude, double longitude) {
    int lat = (int) (latitude * 1E6);
    int lng = (int) (longitude * 1E6);
    return new GeoPoint(lat, lng);
}

}

here is my Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="il.co.toeat" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />


<application android:label="@string/app_name" android:icon="@drawable/icon" android:name=".views.MainApplication">
    <uses-library android:name="com.google.android.maps" />

    <activity  android:name=".views.SplashActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar" android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".views.ViewportActivity"
              android:windowSoftInputMode="adjustPan|adjustResize"
              android:label="@string/app_name"
              android:configChanges="locale"
              android:screenOrientation="portrait"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
</application>

hackp0int
  • 4,052
  • 8
  • 59
  • 95
  • See these links - [MapView in Fragment](http://stackoverflow.com/questions/9959072/mapview-in-fragment-ics) -[MapView with Fragment](https://gist.github.com/977234) - [MapView in Listfragment](http://blog.xavirigau.com/?p=39) - [Map Fragment](https://github.com/inazaruk/map-fragment) – Praveenkumar Aug 09 '12 at 10:49
  • Have you found a solution? I am having similar problem + I want to support API 8 and above. :( – Sufian Apr 25 '13 at 13:23
  • @Sufian yes I have found one. – hackp0int Apr 25 '13 at 14:00
  • @Sufian you just have to add Instance of map inside of view – hackp0int Apr 25 '13 at 14:01
  • @IamStalker did you create the Map in a `MapActivity` and then use it in your `Fragment`? Can you please post the code? Or better answer your own question so that everyone gets your help? :) – Sufian Apr 26 '13 at 05:05
  • Yes I will do that m8, that would not be a problem – hackp0int Apr 26 '13 at 07:52
  • @IamStalker still waiting for your solution. :) – Sufian May 13 '13 at 12:54
  • @IamStalker I guess putting a Google Map with JavaScript will work fine as well. Since I need to put one pin only. Still, it would be helpful for others with the same issue we had. :) – Sufian May 20 '13 at 12:57
  • @Sufian I'm really sorry, I'm so busy at work, that I just don't have any time to put an answer here, I will gladly do it, in couple of days. Sorry. – hackp0int May 20 '13 at 14:08

1 Answers1

-1

You can't do it in a such way with Google Map API.

From December 2012 you could use MapFragment and SupportMapFragment with Google Map API v2, more info here: https://developers.google.com/maps/documentation/android/

Edit

I think you don't understand me. You should not be able to put MapView in Fragment in the way you do.

It's not typically to use a MapView in simple Fragment (before new MapFragments). There is a hack which allows it, you could read about it here https://stackoverflow.com/a/8126287/1233021 BuT I think it's better to use new MapFragments when you don't need to do any overhead... They are available since the 12th of December. The link is in previous message.

BTW: There was a problem but with other error https://stackoverflow.com/a/9448871/1233021

Community
  • 1
  • 1
m190
  • 351
  • 5
  • 11