Сбой моего приложения для Android при переключении на действие

#android

#Android

Вопрос:

В моем приложении есть три активации: 1-й — калькулятор BMI, 2-й — вызов больницы, подключенный к базе данных, 3-й — действие карты (которое сбой) всякий раз, когда я нажимаю на значок карты. И, пожалуйста, для всех, кто собирается ответить на мой вопрос, пожалуйста, обратите внимание на мое имя и обратите внимание, что я идиот в разработке, и я буквально ничего не знаю, поэтому, если вы дадите мне решение, я был бы признателен, если вы объясните мне, как новичку, спасибо.

мой код:

XML

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@ id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HospitalMap">

    <fragment
        android:id="@ id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@ id/constraintLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context=".HospitalMap" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/constraintLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@ id/activity_map_BMI_text_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="bmiView"
            android:text="BMI"
            android:textColor="@color/text_color"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@ id/activity_map_BMI_image_button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="@ id/activity_map_BMI_image_button" />

        <TextView
            android:id="@ id/activity_map_emergency_text_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="emergencyView"
            android:text="EMERGENCY"
            android:textColor="@color/text_color"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="@ id/activity_map_BMI_text_button"
            app:layout_constraintEnd_toEndOf="@ id/activity_map_emergency_image_button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="@ id/activity_map_emergency_image_button"
            app:layout_constraintTop_toTopOf="@ id/activity_map_BMI_text_button" />

        <TextView
            android:id="@ id/activity_map_map_text_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="mapView2"
            android:text="MAP"
            android:textColor="@color/text_color"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="@ id/activity_map_emergency_text_button"
            app:layout_constraintEnd_toEndOf="@ id/activity_map_map_image_button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="@ id/activity_map_map_image_button"
            app:layout_constraintTop_toTopOf="@ id/activity_map_emergency_text_button" />

        <ImageView
            android:id="@ id/activity_map_BMI_image_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:onClick="bmiView"
            app:layout_constraintBottom_toTopOf="@ id/activity_map_BMI_text_button"
            app:layout_constraintEnd_toStartOf="@ id/activity_map_emergency_image_button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:srcCompat="@drawable/icons8_sports_mode_48px" />

        <ImageView
            android:id="@ id/activity_map_emergency_image_button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:onClick="emergencyView"
            app:layout_constraintBottom_toBottomOf="@ id/activity_map_BMI_image_button"
            app:layout_constraintEnd_toStartOf="@ id/activity_map_map_image_button"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@ id/activity_map_BMI_image_button"
            app:layout_constraintTop_toTopOf="@ id/activity_map_BMI_image_button"
            app:srcCompat="@drawable/icons8_hospital_3_48px" />

        <ImageView
            android:id="@ id/activity_map_map_image_button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:onClick="mapView2"
            app:layout_constraintBottom_toBottomOf="@ id/activity_map_emergency_image_button"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@ id/activity_map_emergency_image_button"
            app:layout_constraintTop_toTopOf="@ id/activity_map_emergency_image_button"
            app:srcCompat="@drawable/icons8_map_60px" />
    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
 

Активность

 package com.softwareclinics.ourhealth;

import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;


public class HospitalMap extends FragmentActivity implements OnMapReadyCallback {
    protected LocationManager locationManager;
    protected LocationListener locationListener;
    protected Context context;
    TextView txtLat;
    String lat;
    String provider;
    protected String latitude, longitude;
    protected boolean gps_enabled, network_enabled;

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.mapView);
        mapFragment.getMapAsync(this);

    }


    @Override
    public void onMapReady(GoogleMap googleMap) {


        mMap = googleMap;


        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.setMinZoomPreference(11);


        // Care National Hospital Marker
        LatLng care = new LatLng(24.6796703, 46.7268578);
        mMap.addMarker(new MarkerOptions().position(care).title("National Care Hospital"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(care));

        // Kingdom Hospital Marker
        LatLng Kingdom = new LatLng(24.8013866, 46.6549079);
        mMap.addMarker(new MarkerOptions().position(Kingdom).title("Kingdom Hospital"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Kingdom));

        // Alhabib Hospital Marker
        LatLng Habib = new LatLng(24.7213231, 46.7747423);
        mMap.addMarker(new MarkerOptions().position(Habib).title("Alhabib Hospital"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Habib));

        // Mouwasat Hospital Marker
        LatLng Mouwasat = new LatLng(24.7871558, 46.7328539);
        mMap.addMarker(new MarkerOptions().position(Mouwasat).title("Mouwasat Hospital"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Mouwasat));

        // King Salman Hospital Marker
        LatLng Salman = new LatLng(24.6071859, 46.6420467);
        mMap.addMarker(new MarkerOptions().position(Salman).title("King Salman Hospital"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Salman));

    }


    public void emergencyView(View view) {
        Intent intent = new Intent(this, EmergencyActivity.class);
        startActivity(intent);
    }

    public void mapView2(View view) {
        Toast.makeText(this, "You are in BMI now", Toast.LENGTH_LONG).show();
    }

    public void bmiView(View view) {
        Intent intent = new Intent(this, bmi.class);
        startActivity(intent);
    }

}
 

Комментарии:

1. Что за сбой вы получаете? Пожалуйста, добавьте журнал.

2. где мне найти журнал в Android studio? а что, если его слишком долго вставлять сюда?