Android Studio Project can't find file in raw folder

33 views Asked by At

I am trying to style my map that i hace implemented in my application. The map is working fine, but when i tried to put a style on it, it produces an error.

These are the lines that are relevant to the problem:

fun MapViewContainer(modifier: Modifier = Modifier, currentLatLng: LatLng) {
    val context = LocalContext.current
    val mapView = remember {
        MapView(context).apply {
            onCreate(Bundle())
            getMapAsync { googleMap ->
                googleMap.addMarker(MarkerOptions().position(currentLatLng).title("Localització Actual"))
                googleMap.uiSettings.isZoomControlsEnabled = true
                googleMap.uiSettings.isZoomGesturesEnabled = true
                googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), res.raw.map_style))

there are some parameters more, but those work fine. The problem is that it says there is an unresolved reference to res.raw.map_style, but that file does exist. I include an image:

image of the structure of the project

I hace tried to rebuild and reset Android Studio, but nothing seems to work. If someone can provide a solution, i would be very grateful. Thank you!!

2

There are 2 answers

4
Nirali Pandya On

Use it like googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.map_style)

Instead of res.raw You should use R.raw

1
Jonus On

It's missing the closing parenthesis for the setMapStyle method and the closing brace for the lambda expression passed to getMapAsync. Also wrap the setMapStyle call in a try-catch block to handle any exceptions.