Ok so I've searched and searched, I'm on the final hurdle of getting this example project working, but now it keeps failing to launch on my phone (Galaxy S4) when I try to implement android-maps-extensions 2.0 (I have loads to markers to add to the map, but need them dynamically)
I have the libraries all setup and working as they should, but whenever I change my MapFragment codes to SupportMapFragment the app crashes and doesn't open. If I leave everything as is the app loads on my phone fine
LogCat
01-20 12:24:53.382: E/AndroidRuntime(21636): FATAL EXCEPTION: main
01-20 12:24:53.382: E/AndroidRuntime(21636): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.mypackage/com.me.mypackage.MainActivity}: java.lang.NullPointerException
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.access$700(ActivityThread.java:159)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.os.Looper.loop(Looper.java:137)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.main(ActivityThread.java:5419)
01-20 12:24:53.382: E/AndroidRuntime(21636): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 12:24:53.382: E/AndroidRuntime(21636): at java.lang.reflect.Method.invoke(Method.java:525)
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
01-20 12:24:53.382: E/AndroidRuntime(21636): at dalvik.system.NativeStart.main(Native Method)
01-20 12:24:53.382: E/AndroidRuntime(21636): Caused by: java.lang.NullPointerException
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.me.mypackage.MainActivity.setUpMapIfNeeded(MainActivity.java:102)
01-20 12:24:53.382: E/AndroidRuntime(21636): at com.me.mypackage.MainActivity.onCreate(MainActivity.java:76)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.Activity.performCreate(Activity.java:5372)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
01-20 12:24:53.382: E/AndroidRuntime(21636): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
Manifest XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.mypackage"
android:id="@+id/theMap"
android:name="com.androidmapsextensions.SupportMapFragment"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.me.mypackage.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mhmedia.fuelfinder.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="myAPI_KEY" />
<activity
android:name="com.me.mypackage.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"></meta-data>
</application>
</manifest>
MainActivity Class
public class MainActivity extends FragmentActivity implements LocationListener,
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, LocationSource {
private GoogleMap mMap;
private OnLocationChangedListener mListener;
private LocationManager locationmanager;
GoogleMap googlemap;
LatLng myposition;
ArrayList<Entry> entries = new ArrayList<Entry>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(locationmanager != null){
boolean gpsIsEnabled = locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean networkIsEnabled = locationmanager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(gpsIsEnabled){
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this);
}
else if(networkIsEnabled)
{
locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
}
else
{
Toast.makeText(this, "GPS is not enabled", Toast.LENGTH_SHORT).show();
}
setUpMapIfNeeded();
showmypoi();
}
}
@Override
public void onPause()
{
if(locationmanager != null){
locationmanager.removeUpdates(this);
}
super.onPause();
}
@Override
public void onResume(){
super.onResume();
setUpMapIfNeeded();
if(locationmanager != null){
mMap.setMyLocationEnabled(true);
}
}
private void setUpMapIfNeeded() {
if (mMap == null){
mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.the_map)).getExtendedMap();
if (mMap != null){
setUpMap();
}
mMap.setLocationSource(this);
}
}
private void showmypoi() {
InputStream is = null;
is = this.getResources().openRawResource(R.raw.markers);
ArrayList<Entry> entries = (ArrayList<Entry>) new ParserParsing().parse(is);
for (int i = 0; i < entries.size(); i++){
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.the_map)).getExtendedMap();
mMap.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));
/* mMap.addMarker(new MarkerOptions()
.position(lng)
.icon(BitmapDescriptorFactory.fromResource(getResources().getIdentifier(icon, "drawable", getPackageName())
}
}
private void setUpMap() {
mMap.setMyLocationEnabled(true);
}
@Override
public void activate(OnLocationChangedListener listener) {
mListener = listener;
}
@Override
public void deactivate() {
mListener = null;
}
@Override
public void onConnectionFailed(ConnectionResult result) {}
@Override
public void onConnected(Bundle connectionHint) {}
@Override
public void onDisconnected() {}
public void onCameraChange(CameraPosition cameraPosition){
}
@Override
public void onLocationChanged(Location location) {
if( mListener != null){
mListener.onLocationChanged( location );
LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds;
if(!bounds.contains(new LatLng(location.getAltitude(), location.getLongitude())));{
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
}
}
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Provider Disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Provider Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Toast.makeText(this, "Status Changed", Toast.LENGTH_SHORT).show();
}
}
What am I doing wrong? I'm wracking my brains trying to figure this out. I have so many markers to add to the map I need the clustering abilities of the map extensions
Thank you
I have figured it out. I wasn't importing com.androidmapsextensions.SupportMapFragment in my layout file, I was importing com.google.android.gms.maps.SupportMapFragment hence the map wasn't loading.