Question: hello I have an error for my android studio code that uses api 2 7 and it is about a gps app. Can you please

hello I have an error for my android studio code that uses api 27 and it is about a gps app. Can you please locate the errors and fix them for me because it has a red underline underneath it?I want to be able to run it but so far nobody helped fix it. I will give you the code for MainActivity.java and I will give you a screenshot of the errors. If you need any of the other codes for the java classes please be sure to tell me otherwise here is the code of MainActivity.java:
package com.example.gpslocationapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private LocationManager locationManager;
private DatabaseHelper dbHelper;
private TextView tvLocationDetails;
private Button btnRecordLocation;
private ListView locationListView;
private ArrayList locationList;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views and database helper
tvLocationDetails = findViewById(R.id.tvLocationDetails);
btnRecordLocation = findViewById(R.id.btnRecordLocation);
locationListView = findViewById(R.id.locationListView);
dbHelper = new DatabaseHelper(this);
// Setup the location list
locationList = new ArrayList>();
ArrayAdapter adapter = new ArrayAdapter>(this, android.R.layout.simple_list_item_1, locationList);
locationListView.setAdapter(adapter);
// Initialize Location Manager
locationManager =(LocationManager) getSystemService(LOCATION_SERVICE);
// Button click to record location
btnRecordLocation.setOnClickListener(v ->{
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, locationListener);
});
}
private final LocationListener locationListener = new LocationListener(){
@Override
public void onLocationChanged(Location location){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
// Show the coordinates
tvLocationDetails.setText("Lat: "+ latitude +", Lon: "+ longitude);
// Save to the database
dbHelper.getWritableDatabase().execSQL("INSERT INTO "+ DatabaseHelper.TABLE_LOCATIONS +"("+
DatabaseHelper.COLUMN_LAT +","+ DatabaseHelper.COLUMN_LON +") VALUES ("+ latitude +","+ longitude +")");
// Add to the location list (for display)
locationList.add("Lat: "+ latitude +", Lon: "+ longitude);
((ArrayAdapter) locationListView.getAdapter()).notifyDataSetChanged();
Toast.makeText(MainActivity.this, "Location Recorded", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){}
@Override
public void onProviderEnabled(String provider){}
@Override
public void onProviderDisabled(String provider){}
};
}
hello I have an error for my android studio code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!