Android - Gridlayout android.support.v7.widget.GridLayout cannot be cast to android.widget.GridLayout

 ̄綄美尐妖づ 提交于 2019-11-27 09:23:25

Yes from your error log ,

android.support.v7.widget.GridLayout cannot be cast to android.widget.GridLayout
                      at devector.dom.gridtest.MainActivity.onCreate(MainActivity.java:21)

you can change your casting like this way to solve your problem

android.support.v7.widget.GridLayout grid = (android.support.v7.widget.GridLayout)findViewById(R.id.grid);

Replace

'import android.widget.GridLayout;'

by

'import android.support.v7.widget.GridLayout;'

This worked for me . Hope this will work for you.......

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.

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

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.

Just change the format a little bit: androidx.gridlayout.widget.GridLayout newGrid= (androidx.gridlayout.widget.GridLayout) findViewById (R.id.yourGrid);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!