我在我的项目中使用了BottomNavigationView,它工作正常。除了我现在在我的3. Activity上添加了BottomNavigationView之外,只有在那里它引发异常,并且我的代码找不到问题。
这是我的活动中的代码:
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) { //when Bottom Navigationbar is clicked
R.id.navigation_Auskunft -> { //Different Activities can be opened
val intent = Intent(this, fahrplanmap::class.java) //Opens fahrplanmap Class
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Abfahrtsmonitor -> {
val intent = Intent(this, Abfahrtsmonitor::class.java) //Opens fahrplanmap Class
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Karte -> {
val intent = Intent(this, MapsAnzeigeActivity::class.java) //Opens fahrplanmap Class
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Meldungen -> {
return@OnNavigationItemSelectedListener true
}
R.id.navigation_weiteres -> {
return@OnNavigationItemSelectedListener true
}
}
false
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.abfahrtsmonitor)
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener) //Here it is red undlerined with the error
....
}
我的xml文件的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Abfahrtsmonitor">
<EditText
android:id="@+id/editText"
android:layout_width="360dp"
android:layout_height="47dp"
android:ems="10"
android:hint="Suche"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="7dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/Recycleview"
android:layout_width="370dp"
android:layout_height="441dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="4dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<android.support.design.widget.BottomNavigationView
android:layout_width="368dp"
android:layout_height="48dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="511dp"
android:id="@+id/navigation"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"/>
和其他活动中的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fahrplanmap">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
在其他活动中,我以完全相同的方式定义了它们,并且在那里完全没有问题。
我上传了一张鼠标悬停有错误的图片
答案 0 :(得分:1)
可能是因为您从未在*Run-time error '1004':
Method 'range' of object '_Global' failed*
方法中初始化+------------------------------------------------------------------------------------------------------+---------------------+-------------+-------------------------------------+------------+
| rhOutcome | rhStartTime | rhAccountNo | rhOperatorName | rhCallRef |
+------------------------------------------------------------------------------------------------------+---------------------+-------------+-------------------------------------+------------+
| PROCESS_COMPLETE | 19/09/2018 00:02:06 | 106874 | Kevin Jones | 8GVHTXUK |
| START_END_CALLOUT_IWORK | 19/09/2018 00:21:44 | 225080 | Claire Miley | SKALW2VR |
| CREATE_JOB_SADC | 19/09/2018 01:07:54 | 141116 | Claire Miley | DK9JSTK8 |
| QUERY_RESOLVED | 19/09/2018 01:16:40 | 106836 | Kevin Jones | J2RFLY8C |
| PROCESS_COMPLETE | 19/09/2018 01:14:01 | 106874 | Kevin Jones | F7K33MPM |
| ADDITIONAL_REF_DATA_CAPTURE_END_SAC | 19/09/2018 01:11:12 | 141590 | Claire Miley | CKLYJPDA |
| ABORT | 19/09/2018 01:28:37 | 225080 | Claire Miley | UY38NRNL |
| PROCESS_COMPLETE | 19/09/2018 01:09:42 | 106874 | Kevin Jones | NQFWC76W |
| CALL_PASSED | 19/09/2018 01:05:50 | 70018 | Kevin Jones | TD7DMDN9 |
| END_CALL | 19/09/2018 01:29:52 | 310523 | Martyn Jones | W76MWX22 |
| CHECK_IN_REMINDER_SAC | 19/09/2018 01:01:01 | 141475 | Claire Miley | GW8YKMGW |
| JOB_NOT_COMPLETE | 19/09/2018 01:00:21 | 141116 | Claire Miley | 5JZA6977 |
| TIMER_SET_SAC | 19/09/2018 00:57:01 | 310739 | Kevin Jones | D5Z69P4T |
| SPAM_EMAIL | 19/09/2018 01:39:52 | 911804 | Margaret Weir | Q6RH25RJ |
| GEN_ENQUIRY_CLOSE_SAC | 19/09/2018 00:54:06 | 833694 | Margaret Weir | 8Z88KU94 |
| ALARM_ACTIAVTION_CLOSE_SAC | 19/09/2018 00:53:16 | 833694 | Martyn Jones | Q2RTWHFT |
| ALARM_ACTIAVTION_CLOSE_SAC | 19/09/2018 00:50:47 | 833694 | Kevin Jones | BXC5UJ6Q |
| ABORT | 19/09/2018 00:48:40 | 316084 | Martyn Jones | AUH3Z5H9 |
| SEND_DETAILS_BY_SMS | 19/09/2018 00:30:14 | 225110 | Claire Miley | T4TS42X3 |
| ABORTED_CALL | 19/09/2018 00:25:09 | 155357 | Kevin Jones | 5G2HZQCA |
| JOB_PASSED | 19/09/2018 02:07:20 | 911983 | Margaret Weir | 2648PN38 |
| PROCESS_COMPLETE | 19/09/2018 02:07:30 | 106874 | Martyn Jones | H7ND6DWQ |
| NO_MESSAGE_DATA | 19/09/2018 02:09:03 | 310169 | Kevin Jones | Z694XH4V |
| JOB_NOT_COMPLETE | 19/09/2018 00:24:11 | 141116 | Claire Miley | TJBWRBQY |
| END_CALL | 19/09/2018 00:17:42 | 310523 | Kevin Jones | T8WPXCU6 |
| CODE_NOT_WORKING_BLUE_RESOLVED | 19/09/2018 02:15:21 | 106836 | Kevin Jones | 63NHPC7N |
| OOH_NO_MESSAGE_DATA | 19/09/2018 02:19:10 | 310169 | Martyn Jones | 62RX9BP3 |
| ABORTED_CALL | 19/09/2018 00:15:49 | 155357 | Martyn Jones | VSAMDWDG |
| END_CALL | 19/09/2018 00:14:25 | 310523 | Kevin Jones | YCAWLGBE |
| END_CALL | 19/09/2018 00:11:03 | 310523 | Kevin Jones | GXRCMQHU |
| ABORT | 19/09/2018 00:10:10 | 140014 | Claire Miley | BQ72RRNR |
| CALL_ANSWERED_PASSED_SAC | 19/09/2018 00:09:56 | 31206 | Martyn Jones | LDTMFJSS |
| END_CALL | 19/09/2018 00:05:24 | 310523 | Martyn Jones | VJLFGBL6 |
| JOB_UPDATE_DATA | 19/09/2018 00:03:01 | 911804 | Margaret Weir | 2L4WHNQB |
| TIMER_SET_SAC | 19/09/2018 00:01:17 | 310739 | Martyn Jones | XY84B498 |
| PROCESS_COMPLETE | 19/09/2018 01:18:46 | 106874 | Kevin Jones | ZYGREQ7D |
| SPAM_EMAIL | 19/09/2018 01:23:21 | 911804 | Margaret Weir | Z9DZNN2V |
| END_CALL | 19/09/2018 01:28:51 | 310523 | Kevin Jones | 3YY8YPDB |
| END_CALL | 19/09/2018 01:29:34 | 310523 | Kevin Jones | AGJP82H8 |
| NO_CALLOUT_REQUIRED | 19/09/2018 01:07:54 | 141116 | Claire Miley | DK9JSTK8 |
| ETA_ADVICE_GIVEN_SAC | 19/09/2018 01:30:14 | 911968 | Margaret Weir | PKTXU2JX |
| END_CALL | 19/09/2018 01:37:49 | 310523 | Martyn Jones | AP7CUYA4 |
| ABORTED_CALL | 19/09/2018 01:55:06 | 155357 | Martyn Jones | MZHEW6SU |
| JOB_NOT_COMPLETE | 19/09/2018 02:13:31 | 141116 | Claire Miley | BAYYPWJZ |
| MESSAGE | 19/09/2018 02:56:18 | 106871 | Martyn Jones | YV3AXSWP |
| ABORT | 19/09/2018 02:19:16 | 140014 | Claire Miley | 9C82J6M5 |
| NO_MESSAGE_SAC | 19/09/2018 02:23:19 | 106871 | Kevin Jones | AVTASU7U |
| NO_MESSAGE_SAC | 19/09/2018 02:24:03 | 106871 | Kevin Jones | JNE3J723 |
| MESSAGE | 19/09/2018 02:24:46 | 106871 | Kevin Jones | F8MVAHSP |
| DECLINE_TO_LEAVE_DETAILS_SAC | 19/09/2018 02:27:09 | 141590 | Claire Miley | AKYGGB6M |
| MESSAGE | 19/09/2018 02:29:11 | 106866 | Martyn Jones | 7VEC5EY3 |
| TECH_SUPPORT_NEW_PATCH_FAILED | 19/09/2018 02:29:11 | 911248 | Margaret Weir | ZCXZD8WG |
| END_CALL | 19/09/2018 02:42:46 | 310523 | Kevin Jones | G2RRM5BT |
| MESSAGE | 19/09/2018 03:18:47 | 106871 | Kevin Jones | QEG7CUWC |
| OOH_FAULT_CLS | 19/09/2018 02:46:46 | 911667 | Margaret Weir | 8UW2M9LH |
| NO_MESSAGE_SAC | 19/09/2018 02:48:24 | 106871 | Martyn Jones | CZWBPZ9U |
| NO_MESSAGE_SAC | 19/09/2018 02:49:05 | 106871 | Kevin Jones | QLHT6UBT |
| MESSAGE | 19/09/2018 02:49:41 | 106871 | Martyn Jones | N4WVGDVM |
| ABORT | 19/09/2018 02:52:53 | 190001 | Kevin Jones | 6GLUHVSG |
| END_CALL | 19/09/2018 01:32:35 | 310523 | Martyn Jones | KZ759EYC |
| ABORTED_CALL | 19/09/2018 01:55:00 | 155357 | Martyn Jones | CBT8HUFL |
| END_CALL | 19/09/2018 02:55:05 | 310523 | Kevin Jones | D3XMG9W6 |
| ABORT | 19/09/2018 01:56:41 | 310470 | Martyn Jones | C3BRA65U |
| TIMER_SET_SAC | 19/09/2018 01:59:10 | 310739 | Martyn Jones | 54Q67QUK |
| JOB_UPDATED | 19/09/2018 04:48:12 | 141116 | Claire Miley | Y8T6SZ4U |
| ABORT | 19/09/2018 02:00:05 | 911626 | Margaret Weir | V2Y5M3LS |
| DETAILS_PASSED_DATA | 19/09/2018 02:02:58 | 141371 | Claire Miley | J6HRFM8F |
| SAVE_AND_CLOSE | 19/09/2018 03:01:13 | 310827 | Kevin Jones | 6A6Q9KYU |
| TIMER_SET_SAC | 19/09/2018 03:01:50 | 310739 | Martyn Jones | 9CV8DWXN |
| MESSAGE | 19/09/2018 03:07:20 | 106871 | Martyn Jones | U9BC3GNC |
| JOB_PASSED | 19/09/2018 03:09:08 | 911982 | Margaret Weir | GHUQWW3T |
| CREATE_JOB_SADC | 19/09/2018 03:16:13 | 141116 | Claire Miley | 8YT5XA5U |
| JOB_NOT_COMPLETE | 19/09/2018 02:37:41 | 141116 | Claire Miley | 2FEBSCJJ |
| ABORT | 19/09/2018 03:24:30 | 140014 | Claire Miley | GZ2CYXJH |
| QUERY_RESOLVED | 19/09/2018 04:23:11 | 106836 | Martyn Jones | GSA6QACH |
| ABORT | 19/09/2018 02:53:09 | 190001 | Martyn Jones | 2FLFK95G |
| NEW_ORDER | 19/09/2018 04:48:47 | 310722 | Martyn Jones | BMW4G3WA |
| OOH_NO_MESSAGE_DATA | 19/09/2018 02:14:42 | 310169 | Martyn Jones | RZB86GEC |
| CREATE_JOB_SADC | 19/09/2018 04:54:19 | 141116 | Claire Miley | Q2YWAJP7 |
| NEXT_PRODUCT | 19/09/2018 05:09:32 | 310169 | Martyn Jones | RMD3KLZT |
| END_CALL | 19/09/2018 03:08:42 | 310523 | Kevin Jones | YRY52DEU |
| NO_CALLOUT_REQUIRED | 19/09/2018 03:16:13 | 141116 | Claire Miley | 8YT5XA5U |
| CLOSE_APPLICATION | 19/09/2018 05:00:25 | 911626 | Margaret Weir | 8J6T9BFK |
| NFU_ALREADY_ACCEPTED_SAC | 19/09/2018 03:23:22 | 911982 | Margaret Weir | V4G3BD2X |
| SEND_SMS | 19/09/2018 05:00:25 | 911626 | Margaret Weir | 8J6T9BFK |
| ALL_JOBS_UPDATED | 19/09/2018 04:48:12 | 141116 | Claire Miley | Y8T6SZ4U |
| ABORT | 19/09/2018 05:28:35 | 225080 | Claire Miley | D9TUGKZH |
| JOB_UPDATED | 19/09/2018 04:54:18 | 141116 | Claire Miley | Q2YWAJP7 |
| END_CALL | 19/09/2018 03:25:26 | 310523 | Martyn Jones | 2WNTZN73 |
| END_CALL | 19/09/2018 05:26:40 | 310523 | Martyn Jones | GB2MK7RW |
| TIMER_SET_SAC | 19/09/2018 03:57:51 | 310739 | Kevin Jones | MTXW2RPJ |
| JOB_NOT_COMPLETE | 19/09/2018 04:08:21 | 141116 | Claire Miley | KXCN3QSF |
| ADDITIONAL_REF_DATA_CAPTURE_END_SAC | 19/09/2018 04:12:04 | 141590 | Claire Miley | LNQVW7NJ |
| SEND_EMAIL | 19/09/2018 05:00:25 | 911626 | Margaret Weir | 8J6T9BFK |
| SEND_SMS | 19/09/2018 05:00:25 | 911626 | Margaret Weir | 8J6T9BFK |
| NEW_ORDER | 19/09/2018 04:28:29 | 310722 | Martyn Jones | 6CFPCDD6 |
+------------------------------------------------------------------------------------------------------+---------------------+-------------+-------------------------------------+------------+
。
在BottomNavigationView
方法内部:
onCreate()
然后:
onCreate()
此外,请勿重复使用相同的ID:BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
以下是使用navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
的一个很好的示例:https://github.com/hitherejoe/BottomNavigationViewSample/
答案 1 :(得分:1)
我认为您的导入语句有问题。
似乎在navigation
和abfahrtsmonitor.xml
中都找到了ID为activity_fahrplanmap.xml
的元素。由于它们都是导入的,因此无法导入您的BottomNavigationView
的分辨率(分辨率模糊)。
如果同时需要导入abfahrtsmonitor.xml
和activity_fahrplanmap.xml
,则应在其中一个文件中重命名ID为navigation
的元素。