Following the example given here, I created the application, I have 2 files here (activity_main.xml and activity_maps.xml). In the end, I inserted a code snippet into content_main.
When you start the application through the phone, the application crashes and writes “Application Stopped”. What is the problem?
Here is a crash:
12-17 22: 59: 15.899 1719-1719 /? E / NotificationService: WARNING: In a future release: this will crash the app: com.android.providers.downloads
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { static final LatLng TutorialsPoint = new LatLng(21 , 57); private GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. try { if (googleMap == null) { googleMap = ((MapFragment) getFragmentManager(). findFragmentById(R.id.map)).getMap(); } googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); Marker TP = googleMap.addMarker(new MarkerOptions(). position(TutorialsPoint).title("TutorialsPoint")); } catch (Exception e) { e.printStackTrace(); } } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { googleMap = googleMap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } }