运算符==不能应用于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添加到现有Java项目会打破Android Studio gradle消息错误
- Android的kotlin和房间持久性库不建设
- kotlin翻新 – 背景粘性并发标记扫描GC释放65326(1448KB)AllocSpace对象,62(1736KB)LOS对象,
- FragmentManager在Kotlin中抛出IllegalArgumentException
- 房间持久性:错误:实体和Pojos必须有一个可用的公共构造函数
- 无法初始化Kotlin中的对话框中的按钮
- 使用Kotlin的房间,建立数据库时得到异常
- 错误:执行失败的任务':app:kaptDebugKotlin'
- 在使用kotlin时,使用实体和Dao文件的正式/正确的方式是什么?