错误:
总共有三个片段。 从我的第三个片段到第一个片段之后,发生了错误。从第二个片段到第一个片段时,我的应用程序不会崩溃。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
代码:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
for (state in 0..user.StateName_.size-1){
state_name.add(user.StateName_[state])
state_id.add(user.StateId_[state])
}
spinnerTemp.adapter = ArrayAdapter(this.context!!, android.R.layout.simple_spinner_dropdown_item,state_name)
spinnerTemp.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
city_name.clear()
city_state_id.clear()
city_id.clear()
for (state in 0..user.CityName_.size - 1) {
city_state_id.add(user.CityStateId_[state])
if (state_id[position] == city_state_id[state]) {
city_name.add(user.CityName_[state])
city_id.add(user.CityId_[state])
}
}
spinnerTemp2.adapter = ArrayAdapter(
this@nameFrag.context!!,
android.R.layout.simple_spinner_dropdown_item,
city_name
)
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
Toast.makeText(this@nameFrag.context,"${city_id}",Toast.LENGTH_SHORT).show()
}
})
spinnerTemp2.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
}
} )
get_name.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int,
count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int,
before: Int, count: Int) {
if(check_pass(s.toString()) == true){
button14.setOnClickListener {
val intent = Intent(this@nameFrag.context, Profile2::class.java)
startActivity(intent)
}
}
else if(check_pass(s.toString()) == false)
button14.setOnClickListener{
Toast.makeText(activity?.applicationContext,"No User Found", Toast.LENGTH_LONG).show()
}
}
})
}
这是我刚刚编写的一段有趣的代码,而且我是android或编程领域的新手,所以我无法弄清楚出了什么问题。
感谢您的帮助。
我不知道是什么原因造成的。
答案 0 :(得分:1)
尝试使用“ selectedItemView:视图?”而不是onItemSelected回调中的参数中的“ selectedItemView:View”,然后看看会发生什么。这些方法期望selectedItemView具有可为null的类型。