I want to create a GridLayout able to run in all the APIs.
The thing is, when i use GridLayout instead of android.support.v7.widget.GridLayo
Replace
import android.widget.GridLayout;
with
import android.support.v7.widget.GridLayout;
This was my issue.
Caused by: java.lang.ClassCastException: android.support.v7.widget.GridLayout cannot be cast to android.widget.GridLayout at devector.dom.gridtest.MainActivity.onCreate(MainActivity.java:21)
=> From this line, it's clear that you must be importing and referring to android.widget.GridLayout
where as you have taken android.support.v7.widget.GridLayout
in XML layout. Use and refer either of any in both layout and class file.
Just change the format a little bit: androidx.gridlayout.widget.GridLayout newGrid= (androidx.gridlayout.widget.GridLayout) findViewById (R.id.yourGrid);
I got the same issue. I solved it by using the GridLayout from package android.support.v7.widget.GridLayout
, since I was previously using the android.widget.GridLayout package
which gave me the error.
import androidx.gridlayout.widget.GridLayout
Do this in you MainActiviy sheet.
You should edit the import.android.widget.GridLayout
as
import androidx.gridlayout.widget.GridLayout
I had the same issue and I just go to activity_main.xml
and replaced
android.support.v7.widget.GridLayout
to this:
android.widget.GridLayout