Android Google Map NearBy Place - java.lang.NullPointerException:CameraUpdateFactory未初始化

时间:2016-06-04 15:27:06

标签: java android google-maps-android-api-2 android-maps-v2

这是我的第一个Google Map API安卓应用。我正在使用谷歌地方服务找到附近的地方。但是当我尝试使用' 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)

以下是我的活动代码:mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(start, 15));中的错误 我不知道是什么导致了这个错误。



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);
            }
        });


    }




我是这个东西的新手,所以任何帮助将不胜感激。非常感谢!如果需要,我会上传更多详细信息。

0 个答案:

没有答案