Anyone see what I'm doing incorrectly? I get the f...
# compose
b
Anyone see what I'm doing incorrectly? I get the following error here
Copy code
val icon = +imageResource(R.drawable.ic_my_location_white_24dp)
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference Something to note: Using setViewContent instead of setContent since I'm using a custom map view
Copy code
class MainActivity : AppCompatActivity() {
    val mapContext = MapContext()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewContent {
            AppTheme {
                MapStack(mapContext = mapContext)
            }
        }
    }
}

@Composable
fun MapStack(webMap: WebMap = WebMap(), mapContext: MapContext) {
    Stack {
        MapComponent(mapContext = mapContext, map = webMap.map)

        aligned(Alignment.BottomRight){
            val icon = +imageResource(R.drawable.ic_my_location_white_24dp)
            FloatingActionButton(
                        icon = icon,
                        modifier = Spacing(left = 8.dp, top = 8.dp, right = 20.dp, bottom = 48.dp)
                )
        }
    }
}
t
Maybe it is because your ressource is a VectorDrawable and the default FloatingActionButton only accepts Image as input? I created a custom Composable for this:
Copy code
@Composable
fun FloatingActionButton(
        @DrawableRes resId: Int,
        modifier: Modifier = Modifier.None,
        onClick: (() -> Unit)? = null,
        shape: Shape = CircleShape,
        color: Color = (+MaterialTheme.colors()).primary,
        elevation: Dp = 6.dp) {
    androidx.ui.material.FloatingActionButton(onClick = onClick, modifier = modifier, shape = shape, color = color, elevation = elevation) {
        val icon = +vectorResource(resId)
        DrawVector(vectorImage = icon, tintColor = (+MaterialTheme.colors()).onPrimary)
    }
}
b
Yeah, I believe that was part of the problem, thanks. The other problem was using the compose stuff (Stack{}, FloatingActionButton, etc) inside of setcontentview.