Arkadeep G Roy
Arkadeep G Roy

Reputation: 3

Why is Grid Layout causing android studio app to crash?

I am using android studio 3.1.4

The app crashes while exwcuting the following part of the code:

  GridLayout layer=(GridLayout)findViewById(R.id.gridId); //Crashes at this point itself.

        for(int i=0;i<layer.getChildCount();i++) {
            ((ImageView)layer.getChildAt(i)).setImageResource(0);
        }

Upvotes: 0

Views: 806

Answers (1)

Momen Zaqout
Momen Zaqout

Reputation: 1498

The error is you use android.support.v7.widget.GridLayout in the XML file but GridLayout in the code.

to fix it, change this line

  GridLayout layer=(GridLayout)findViewById(R.id.gridId); //Crashes at this point itself.

to

 android.support.v7.widget.GridLayout layer=(android.support.v7.widget.GridLayout)findViewById(R.id.gridId); //Crashes at this point itself.

or just import android.support.v7.widget.GridLayout

Upvotes: 1

Related Questions