Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

532
Vistas
Kotlin null handling - making buttons transparent or hiding them

Why does my app crash after pressing button which makes buttons transparent, it says that Reading a NULL string not supported here.

    lateinit var Button1: Button
    lateinit var Button2: Button


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        Button1= view?.findViewById(R.id.btn1)
        Button2 = view?.findViewById(R.id.btn2)


        Button1?.setBackgroundColor(Color.TRANSPARENT)
        Button2?.setBackgroundColor(Color.TRANSPARENT)

    }

Logs

E/OplusCustomizeRestrictionManager: sInstance is null, start a new sInstance
E/libEGL: Invalid file path for libcolorx-loader.soE/libEGL: Invalid file path for libcolorx-loader.so
E/Parcel: Reading a NULL string not supported here.
E/ScreenmodeClient:  display mode not support 

Please help me quickly.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

According to your code and exception you said, I think the button may be null, but you define it as lateinit, which means you create later but it can not be null.

Firstly you should make sure the buttons exist, then change the button defines as the following:

    var Button1: Button? = null
    var Button2: Button? = null


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        Button1= view?.findViewById(R.id.btn1)
        Button2 = view?.findViewById(R.id.btn2)


        Button1?.setBackgroundColor(Color.TRANSPARENT)
        Button2?.setBackgroundColor(Color.TRANSPARENT)

    }

```
the other way is not to use `?`, because the view has to exit.

```
    lateinit var Button1: Button
    lateinit var Button2: Button


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        Button1= view.findViewById(R.id.btn1)
        Button2 = view.findViewById(R.id.btn2)


        Button1.setBackgroundColor(Color.TRANSPARENT)
        Button2.setBackgroundColor(Color.TRANSPARENT)

    }
```

over 4 years ago · Santiago Trujillo Denunciar

0

TRY this -

OPTION 1-

     lateinit var button1: AppCompatButton
        lateinit var button2: AppCompatButton

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        button1 = view.findViewById(R.id.Button1)
        button2 = view.findViewById(R.id.Button2)

        button1.setBackgroundColor(Color.TRANSPARENT)
        button2.setBackgroundColor(Color.TRANSPARENT)
}

Option 2- Simply add in button -

android:background="@null"

<androidx.appcompat.widget.AppCompatButton
        android:id="@+id/Button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:text="Button1" />
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda