Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:28:37+00:00 2026-06-16T01:28:37+00:00

Why the CameraUpdateFactory class is not working in my project? The app crashes if

  • 0

Why the CameraUpdateFactory class is not working in my project?
The app crashes if it executes the following command:
CameraUpdate pino= CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
If i remove that line (and of course the next one), the code successfully starts and shows the map.
I need the mapView and i need to use the new api v2.
I declare the mapView in layout in this way:

        <com.google.android.gms.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"

    android:id="@+id/mappa"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/buttonBar"

    map:uiZoomControls="false"
     />

then in mainActivity.java i wrote this:

    public class MainActivity extends FragmentActivity    implements LocationListener, LocationSource { 
public static boolean locatingMe=true;
public GoogleMap mappa;
public MapView mapView;
private OnLocationChangedListener onLocationChangedListener;
private LocationManager locationManager;




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

    mapView = (MapView) findViewById(R.id.mappa);
    mapView.onCreate(savedInstanceState);


        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    //You may want to pass a different provider in as the first arg here
    //depending on the location accuracy that you desire
    //see LocationManager.getBestProvider()
    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.NO_REQUIREMENT);
    locationManager.requestLocationUpdates(locationManager.getBestProvider(locationCriteria, true), 1L, 2F, this);

    if (mappa == null) {
        mappa=mapView.getMap();
        //This is how you register the LocationSource
        mappa.setLocationSource(this);
        mappa.getUiSettings().setMyLocationButtonEnabled(false);
        mappa.setMyLocationEnabled(true);
    }


}
@Override
public void onPause()
{
    if(locationManager != null)
    {
        locationManager.removeUpdates(this);
    }
    mapView.onPause();
    super.onPause();
}

@Override
public void onResume()
{
      checkGooglePlayServicesAvailability();
      checkGps();
      mapView.onResume();
      super.onResume();
}
@Override
protected void onDestroy() {
    mapView.onDestroy();
    super.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

@Override
public void activate(OnLocationChangedListener listener) 
{
    onLocationChangedListener = listener;
}

@Override
public void deactivate() 
{
    onLocationChangedListener = null;
}

@Override
public void onLocationChanged(Location location) 
{
    if( onLocationChangedListener != null )
    {
        onLocationChangedListener.onLocationChanged( location );

        //Move the camera to the user's location once it's available!
        //only if locatingMe is true
        if (locatingMe) {
            if (mappa!=null){
                CameraUpdate pino= CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
                        mappa.animateCamera(pino);

            }

        }

    }
}

@Override
public void onProviderDisabled(String provider) 
{
    // TODO Auto-generated method stub
    Toast.makeText(this, "provider disabled", Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderEnabled(String provider) 
{
    // TODO Auto-generated method stub
    Toast.makeText(this, "provider enabled", Toast.LENGTH_SHORT).show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) 
{
    // TODO Auto-generated method stub
    Toast.makeText(this, "status changed", Toast.LENGTH_SHORT).show();
}

The error in the LogCat is the following:

 Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:28:39+00:00Added an answer on June 16, 2026 at 1:28 am

    I solved the problem by adding on the “onCreate” the following lines:

     try {
         MapsInitializer.initialize(this);
     } catch (GooglePlayServicesNotAvailableException e) {
         e.printStackTrace();
     }
    

    the reason is that the CameraUpdateFactory needs to be initilized (even if from documentation it seems that using mapview it shoud be automatically initialized)

    I even replaced “public class MainActivity extends FragmentActivity” with “public class MainActivity extends Activity”. But i think that this last thing it was not needed..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found a few questions on this subject here but their answers do not
I have a Fragment which Extends SupportMapFragment. public class PlaceMapsFragment extends SupportMapFragment { private
I am trying to use the new Google Play Services Lib and embbed Maps
I'm making use of the new Android Google Maps API . I create an
When using Google Maps Android API V2 I'm following the Google Play Services setup
My question is, does anyone know how to set google maps up, to open
The blue dot/arrow isnt showing on my map. Everything else works fine. Am i
Hello I'm trying to add MapView to LinearLayout this is my code: GoogleMap mMap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.