运算符==不能应用于Kotlin中的“Long”和“Int”
我试图在Kotlin中实现Mike Penz的NavigationDrawer( https://github.com/mikepenz/MaterialDrawer )的一部分。 从那时起,我只遇到几个问题,主要是与运营商。 这里是实例化抽屉本身的代码的一部分。 除了在int和Long变量上使用==运算符的位置,Android Studio不会引发任何错误:
// Create the Drawer result = DrawerBuilder() .withSliderBackgroundColor(ContextCompat.getColor(applicationContext, R.color.top_header)) .withActivity(this) .withToolbar(toolbar) .withHasStableIds(true) .withItemAnimator(AlphaCrossFadeAnimator()) .withAccountHeader(headerResult!!) .addDrawerItems( PrimaryDrawerItem().withName(R.string.drawer_item_profile).withIcon(FontAwesome.Icon.faw_user).withIdentifier(1).withSelectable(false).withIconColor(ContextCompat.getColor(applicationContext, R.color.icon_grey)).withTextColor(ContextCompat.getColor(applicationContext, R.color.stroke)), PrimaryDrawerItem().withName(R.string.drawer_item_create).withIcon(FontAwesome.Icon.faw_paint_brush).withIdentifier(2).withSelectable(false).withIconColor(ContextCompat.getColor(applicationContext, R.color.icon_grey)).withTextColor(ContextCompat.getColor(applicationContext, R.color.stroke)), PrimaryDrawerItem().withName(R.string.drawer_item_yaanich_news).withIcon(FontAwesome.Icon.faw_newspaper_o).withIdentifier(3).withSelectable(false).withIconColor(ContextCompat.getColor(applicationContext, R.color.icon_grey)).withTextColor(ContextCompat.getColor(applicationContext, R.color.stroke)), PrimaryDrawerItem().withName(R.string.drawer_item_my_groups).withIcon(FontAwesome.Icon.faw_users).withIdentifier(4).withSelectable(false).withIconColor(ContextCompat.getColor(applicationContext, R.color.icon_grey)).withTextColor(ContextCompat.getColor(applicationContext, R.color.stroke)), PrimaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIdentifier(5).withSelectable(false).withIconColor(ContextCompat.getColor(applicationContext, R.color.icon_grey)).withTextColor(ContextCompat.getColor(applicationContext, R.color.stroke)) ) .withOnDrawerItemClickListener { view, position, drawerItem -> if (drawerItem != null) { var intent: Intent? = null if (drawerItem.identifier == (1) { intent = Intent(this, UserProfileActivity::class.java) } else if (drawerItem.identifier == 2) { intent = Intent(this, YeetActivity::class.java) } else if (drawerItem.identifier == 3) { intent = Intent(this, RssActivity::class.java) } else if (drawerItem.identifier == 4) { intent = Intent(this, GroupsActivity::class.java) } else if (drawerItem.identifier == 5) { intent = Intent(this, UserSettingsActivity::class.java) } if (intent != null) { this.startActivity(intent) } } false } .withSavedInstance(savedInstanceState) .withShowDrawerOnFirstLaunch(true) .build() RecyclerViewCacheUtil<IDrawerItem<*, *>>().withCacheSize(2).apply(result!!.recyclerView, result!!.drawerItems) if (savedInstanceState == null) { result!!.setSelection(21, false) headerResult!!.activeProfile = profile } }
错误:
if (drawerItem.identifier == (1)
if (drawerItem.identifier == 2)
Operator == cannot be applied to 'Long and' 'Int'
只要在你的右边使用很长时间
if (drawerItem.identifier == 1L)
如果你面对的问题< 运算符!=不适用于long和int >解决它只要在你的右边长,即值!= 1L这就是它..
- 用Kotlin在android中声明变量类型的正确方法是什么?
- Kotlin Dokka – 在android studio中找不到Dokka任务
- 在BottomsheetDialog中使用setcontentview时,会出现类似“以下函数都不能用提供的参数调用”的错误
- NoSuchMethodError在Kotlin中使用@Parcelize注释
- 以编程方式在Kotlin中定制TypeFace
- 如何在Android Activity上使用Kotlin扩展函数进行空检查
- 图像视图不会出现在Activity上(在AppCompatActivity上可以)
- 反序列化包含数组的Firestore文档的推荐方法是什么?
- 为什么在从Kotlin调用方法时,在logcat中看不到任何有用的东西?