0

This is my first Google Map API android app. I am doing find nearby place using google place service. But I face the error below when I try to use 'CameraUpdateFactory'

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chinatown.wangjian.chinatown_map/com.chinatown.wangjian.chinatown_map.SimpleDirection}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
at com.google.android.gms.common.internal.zzaa.zzb(Unknown Source)
at com.google.android.gms.maps.CameraUpdateFactory.zzDr(Unknown Source)
at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
at com.chinatown.wangjian.chinatown_map.SimpleDirection.onCreate(SimpleDirection.java:42)

Here is my activity code: Error in mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(start, 15)); I do not have any idea what is causing this error.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_direction);

        mMap = ((SupportMapFragment)getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(start, 15));

        gd = new GoogleDirection(this);
        gd.setOnDirectionResponseListener(new OnDirectionResponseListener() {
            public void onResponse(String status, Document doc, GoogleDirection gd) {
                mDoc = doc;
                mMap.addPolyline(gd.getPolyline(doc, 3, Color.RED));
                mMap.addMarker(new MarkerOptions().position(start)
                        .icon(BitmapDescriptorFactory.defaultMarker(
                                BitmapDescriptorFactory.HUE_GREEN)));

                mMap.addMarker(new MarkerOptions().position(end)
                        .icon(BitmapDescriptorFactory.defaultMarker(
                                BitmapDescriptorFactory.HUE_GREEN)));
            }
        });

        buttonRequest = (Button)findViewById(R.id.buttonRequest);
        buttonRequest.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                v.setVisibility(View.GONE);
                gd.setLogging(true);
                gd.request(start, end, GoogleDirection.MODE_DRIVING);
            }
        });


    }

I'm a newbie at this stuff so any help will be appreciated. thanks so much! And i will upload more details if needed.

Daniel
  • 2,355
  • 9
  • 23
  • 30
Wang Jian
  • 321
  • 5
  • 20
  • Try finding the map on 'onResume' method and then animate. Google maps takes time to load and hence the delay. – nikhil.thakkar Jun 04 '16 at 15:36
  • 1
    Have you looked at [this](http://stackoverflow.com/questions/24448378/java-lang-nullpointerexception-cameraupdatefactory-is-not-initialized-logcat-ex) answer yet? – Daniel Jun 04 '16 at 15:42
  • I try insert: try { MapsInitializer.initialize(this); } catch (GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } I got error: exception'com.google.android.gms.common.GooglePlayServicesNotAvailableException' is never thrown in corresponding try block – Wang Jian Jun 05 '16 at 02:34

0 Answers0