我试图将
ArrayList<Integer>
从片段传递到另一个片段,以下是我的代码。
Kotlin code
companion object {
fun newInstance(categoryId: Int, brandsList: ArrayList<Int>): Fragment {
val fragment = CategoryAllAdsFragment()
fragment.arguments = Bundle()
fragment.arguments!!.putInt(Constant.CATEGORY_ID, categoryId)
fragment.arguments!!.putParcelableArrayList(Constant.BRANDS_LIST, brandsList)
return fragment
类型不匹配。
Required: java.util.ArrayList !
找到:kotlin.collections.ArrayList /* = java.util.ArrayList */
我试图阅读时也是如此。
Kotlin code
try {
val brandsList = arguments!!.getParcelableArrayList<Int>(Constant.BRANDS_LIST)
} catch (ex: Exception) {
throw Exception("brand list cannot be null")
类型参数不在其范围内
预期的。可包邮!
Found: Int
我已经用Java
测试过了,它的工作很好。