I have this code, which, according to my idea, should set the background for nicknames in the chat when you turn on the custom background in the chat. Current file - AppearanceFragment.kt
package com.twoeightnine.root.xvii.features.appearance
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import android.widget.CompoundButton
import android.widget.TextView
import android.content.res.ColorStateList
import android.graphics.Color
import androidx.core.view.isVisible
import com.twoeightnine.root.xvii.base.BaseActivity
import android.view.WindowManager;
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.flask.colorpicker.ColorPickerView
import com.flask.colorpicker.builder.ColorPickerDialogBuilder
import com.twoeightnine.root.xvii.R
import com.twoeightnine.root.xvii.base.BaseFragment
import com.twoeightnine.root.xvii.chats.attachments.gallery.GalleryFragment
import com.twoeightnine.root.xvii.extensions.load
import com.twoeightnine.root.xvii.managers.Prefs
import com.twoeightnine.root.xvii.uikit.Munch
import com.twoeightnine.root.xvii.uikit.paint
import com.twoeightnine.root.xvii.utils.*
import com.twoeightnine.root.xvii.views.LoadingDialog
import global.msnthrp.xvii.uikit.extensions.applyBottomInsetPadding
import global.msnthrp.xvii.uikit.extensions.hide
import global.msnthrp.xvii.uikit.extensions.lowerIf
import global.msnthrp.xvii.uikit.extensions.setVisible
import global.msnthrp.xvii.uikit.utils.color.ColorUtils
import kotlinx.android.synthetic.main.chat_input_panel.*
import kotlinx.android.synthetic.main.fragment_appearance.*
import kotlinx.android.synthetic.main.item_message_in_chat.*
import kotlinx.android.synthetic.main.view_appearance_sample.*
import kotlinx.android.synthetic.main.view_appearance_sample.view.*
import java.io.File
class AppearanceFragment : BaseFragment() {
//...
private fun setback() {
nickname.setBackgroundResource(R.drawable.nick_shape)
}
private fun delback() {
nickname.setBackgroundResource(R.drawable.nick_shape_wo)
}
private fun initViews() {
isLightBefore = Prefs.isLightTheme
switchLightTheme.onCheckedListener = CompoundButton.OnCheckedChangeListener { _, b ->
applyColors()
}
switchLightTheme.isChecked = isLightBefore
if (Prefs.chatBack.isNotEmpty()) {
updatePhoto(Prefs.chatBack)
}
btnGallery.setOnClickListener { openGallery() }
csThemeColor.setOnClickListener {
showColorPicker(currentColor) { color ->
currentColor = color
applyColors()
}
}
switchChatBack.onCheckedListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
llCustomBack.setVisible(isChecked)
setback()
nickname.setBackgroundResource(R.drawable.nick_shape);
if (!isChecked) {
deletePhoto()
delback()
// nickname.setBackgroundResource(R.drawable.nick_shape_wo);
}
}
when starting the program it gives the following error java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundResource(int)" on a null object reference at com.twoeightnine.root.xvii.features.appearance.Appea ranceFragment.setback(AppearanceFragment.kt: 239)
Tried to create in activity and not in fragment but not successfull