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)); } } 
  • 2
    You already asked to attach the code. The application stops due to an error, and the error can be anywhere. Initializing GoogleMap is the place where you implement it. - Eugene Troyanskii
  • Do you mean it? - No Name
  • How is "As a result, I inserted a code fragment in content_main" and the fact that your markup is still from activity_maps? - Android Android
  • Oh, I apologize, corrected ... I just had the content first and then changed it to activate_meps the same problem remained ... - No Name
  • I'll check just in case. You got and added a key for Google maps? - Eugene Troyanskii

1 answer 1

To solve your problem try this:

 String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)", sourceLatitude, sourceLongitude, "Home Sweet Home", destinationLatitude, destinationLongitude, "Where the party is at"); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent); 

Although for the flexibility of your application, I would still recommend that you carefully go through the tutorial on installing google maps https://developers.google.com/maps/documentation/android-api/start . You obviously missed some kind of in your opinion not an important detail that you did not attach to the question.