Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

531
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!