gpt4 book ai didi

android - Lateinit 属性 mScrollView 尚未初始化

转载 作者:行者123 更新时间:2023-11-29 15:34:33 26 4
gpt4 key购买 nike

我不明白为什么会出现这种错误:

kotlin.UninitializedPropertyAccessException: lateinit property mScrollView has not been initialized

我的意思是我有这样的代码:

@BindView(R.id.scroll_view)
lateinit var mScrollView: ScrollView

在这里你可以找到onCreateView

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
AndroidSupportInjection.inject(this)
val view = inflater.inflate(R.layout.fragment_delete_account_reason, container, false)

mUnbinder = ButterKnife.bind(this, view)
ViewUtils.setupUI(view, activity)
hideNextBtnOnKeyboardOpens(mScrollView, mNextBtn)

setupLayout()
mPresenter.getReasonKeyOfDeleteAccount()

return view
}

private fun setupLayout() {
mScrollView.viewTreeObserver.addOnGlobalLayoutListener {
val r = Rect()
mScrollView.getWindowVisibleDisplayFrame(r)
val screenHeight = mScrollView.rootView.height
val keypadHeight = screenHeight - r.bottom

if (keypadHeight > screenHeight * 0.15 && mInput.hasFocus()) { // Keyboard is visible
val bottom = mNbCharactersMax.getBottom() + mNbCharactersMax.getPaddingBottom()
val sy = mScrollView.scrollY
val sh = mScrollView.height
val delta = bottom - (sy + sh)
mScrollView.smoothScrollBy(0, delta)
}
}
}

你可以在这里找到我的 xml。所有其他 ID 工作(每个 ID 匹配)但我只有 scrollView 有问题,我不知道为什么。如果我删除 ScrollView,一切都会正常,但我需要这个。

<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">

<ScrollView
android:id="@+id/scroll_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:animateLayoutChanges="true"
android:layout_marginBottom="@dimen/general_padding"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/delete_account_next"
android:fillViewport="true">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/delete_account_description"
fontPath="fonts/SourceSansPro-SemiBold.ttf"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/general_padding"
android:layout_marginTop="@dimen/general_padding"
android:layout_marginEnd="@dimen/general_padding"
android:letterSpacing="@dimen/general_letter_spacing"
android:text="@string/delete_account_reason_description"
android:textColor="@color/vision"
android:textSize="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingPrefix,SpUsage" />

<RadioGroup
android:id="@+id/delete_account_radio_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginEnd="@dimen/two_third_padding"
android:layout_marginStart="@dimen/two_third_padding"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/delete_account_description">

</RadioGroup>

<android.support.design.widget.TextInputLayout
android:id="@+id/delete_account_input_reason_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/delete_account_reason_specify_hint"
android:layout_marginStart="17dp"
android:layout_marginEnd="17dp"
android:layout_marginTop="@dimen/general_padding"
android:visibility="invisible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/delete_account_radio_group">

<android.support.v7.widget.AppCompatEditText
android:id="@+id/delete_account_input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fontPath="fonts/SourceSansPro-SemiBold.ttf"
tools:ignore="MissingPrefix,SpUsage"
android:imeOptions="actionDone"
android:textColor="@color/jiren"
android:textSize="16dp" />

</android.support.design.widget.TextInputLayout>

<TextView
android:id="@+id/delete_account_reason_nb_caracters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontPath="fonts/SourceSansPro-SemiBold.ttf"
app:layout_constraintTop_toBottomOf="@id/delete_account_input_reason_layout"
app:layout_constraintEnd_toStartOf="@id/delete_account_reason_nb_caracters_max"
android:layout_marginEnd="@dimen/quarter_padding"
android:textColor="@color/wolverine"
android:textSize="14dp"
android:text="0"
android:visibility="invisible"
android:letterSpacing="@dimen/general_letter_spacing"
tools:ignore="HardcodedText,MissingPrefix,SpUsage"/>

<TextView
android:id="@+id/delete_account_reason_nb_caracters_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
fontPath="fonts/SourceSansPro-SemiBold.ttf"
app:layout_constraintTop_toBottomOf="@id/delete_account_input_reason_layout"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="@dimen/general_padding"
android:text="@string/delete_account_reason_specify_max_characters"
android:textColor="@color/wolverine"
android:textSize="14dp"
android:visibility="invisible"
android:letterSpacing="@dimen/general_letter_spacing"
tools:ignore="MissingPrefix,SpUsage"/>

</android.support.constraint.ConstraintLayout>

</ScrollView>

<Button
style="?borderlessButtonStyle"
android:id="@+id/delete_account_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:textSize="17dp"
android:paddingTop="@dimen/half_padding"
android:paddingBottom="@dimen/half_padding"
android:paddingStart="@dimen/one_half_padding"
android:paddingEnd="@dimen/one_half_padding"
android:textAllCaps="false"
android:layout_marginTop="@dimen/double_padding"
android:layout_marginBottom="@dimen/one_half_padding"
android:textColor="@color/white"
android:textAlignment="center"
android:background="@drawable/button_blue"
android:letterSpacing="@dimen/general_letter_spacing"
android:text="@string/delete_account_next_label"
android:enabled="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
fontPath="fonts/SourceSansPro-SemiBold.ttf"
tools:ignore="MissingPrefix,SpUsage"/>

你知道为什么吗?

最佳答案

onCreateView()中初始化mScrollView:

mScrollView = view.findViewById<ScrollView>(R.id.scroll_view)
setupLayout()

关于android - Lateinit 属性 mScrollView 尚未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53871354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com