简体   繁体   English

Android:java.lang.NullPointerException:未初始化CameraUpdateFactory

[英]Android : java.lang.NullPointerException: CameraUpdateFactory is not initialized

I was try to implement automatic right zoom level to show all markers. 我试图实现自动右缩放级别来显示所有标记。 But, I' getting Null Pointer exception. 但是,我得到Null Pointer异常。 Here is my code : 这是我的代码:

public class LocationMarkers extends FragmentActivity {
    private static GoogleMap supportMap;
    private ArrayList<LatLng> gp = new ArrayList<LatLng>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.location_marker);
        locationMarkers();

    }

    public void locationMarkers()
    {
        /*Implement Location Markers*/
        BufferedReader jsonReader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.map)));
        StringBuilder jsonBuilder = new StringBuilder();
        try {
            for (String line = null; (line = jsonReader.readLine()) != null;) {
                jsonBuilder.append(line).append("\n");
            }

            JSONTokener tokener = new JSONTokener(jsonBuilder.toString());
            JSONArray jsonArray = new JSONArray(tokener);


            for (int index = 0; index < jsonArray.length(); index++) 
            {

                JSONObject jsonObject = jsonArray.getJSONObject(index);
                double getLat = jsonObject.getJSONObject("point").getDouble("lat");
                double getLng = jsonObject.getJSONObject("point").getDouble("long");
                String name   = jsonObject.getString("name");
                LatLng myLoc = new LatLng(getLat, getLng);
                gp.add(myLoc);
                Log.d("Long", Double.toString(getLng));             
                FragmentManager fmanager = getSupportFragmentManager();
                Fragment fragment = fmanager.findFragmentById(R.id.map);
                SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
                supportMap = supportmapfragment.getMap();
                    if(supportMap!=null){
                        Marker LocMarker = supportMap.addMarker(new MarkerOptions().position(myLoc)
                                  .title(name));

                        }

            }
              LatLngBounds.Builder builder = new LatLngBounds.Builder();
                for(LatLng m : gp) {
                    Log.e("Tag",Double.toString(m.latitude));
                    builder = builder.include(m);
                    }
                LatLngBounds bounds = builder.build();
                int padding = 0;
                CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
                supportMap.moveCamera(cu);
        } catch (FileNotFoundException e) {
            Log.e("jsonFile", "file not found");
        } catch (IOException e) {
            Log.e("jsonFile", "ioerror");
        } catch (JSONException e) {
            Log.e("jsonFile", "error while parsing json");
        }

    }
}

I'm also getting another warning : Google Play services out of date. Requires 2012100 but found 1015 我还得到另一个警告: Google Play services out of date. Requires 2012100 but found 1015 Google Play services out of date. Requires 2012100 but found 1015 I will be happy, If you guys help to find the problem? Google Play services out of date. Requires 2012100 but found 1015我会很高兴,如果你们帮忙找到问题?

1) hope you are testing on device not in emulator. 1)希望您在不在模拟器中的设备上进行测试。 you may get error in emulator, if you still want to test on emulator then comment it. 您可能会在模拟器中出现错误,如果您仍想在模拟器上进行测试然后对其进行评论。 it will work in device perfectly 它将完美地在设备中工作

2) you are getting Google Play services out of date because your google play service library version is not same as your emulator google play service has. 2)您的Google Play服务已过期,因为您的Google Play服务库版本与您的模拟器Google Play服务版本不同。 you have to install updated gms and vending apk file. 你必须安装更新的gms和自动贩卖apk文件。

gms: http://uploaded.net/file/bnzl1si4 gms: http//uploaded.net/file/bnzl1si4

vending: http://www.androidfilehost.com/?fid=9390135922294521859 自动售货: http//www.androidfilehost.com/? fid = 9390135922294521859

hope it will help you. 希望它会对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM