Bryan Lee
12/16/2019, 6:04 PMval 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
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)
)
}
}
}
Timo Drick
12/17/2019, 3:59 PM@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)
}
}
Bryan Lee
12/17/2019, 6:31 PM