728x90

Type 'State<List?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate

 

아래의 두가지 상황일 경우, 에러 발생

Code

@Composable
fun UserScreen(userViewModel:UserViewModel){
    val items: List<User> by userViewModel.fetchUserList.observeAsState()
    UserList(userList = items)
}


@Composable
fun UserScreen(){
 	var value by remember { mutableStateOf("") }
   
}

 

 

방법1

import androidx.compose.runtime.getValue

import androidx.compose.runtime.livedata.observeAsState

 

 

방법2

// for a 'val' variable
import androidx.compose.runtime.getValue

// for a `var` variable also add
import androidx.compose.runtime.setValue

// or just
import androidx.compose.runtime.*

 

 

출처: https://stackoverflow.com/questions/63875411/type-statelistuser-has-no-method-getvaluenothing-kproperty-and-t

728x90

+ Recent posts