androidx.gridlayout.widget.GridLayout无法转换为android.widget.GridLayout [英] androidx.gridlayout.widget.GridLayout cannot be cast to android.widget.GridLayout
本文介绍了androidx.gridlayout.widget.GridLayout无法转换为android.widget.GridLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到错误
"由以下原因引起:java.lang.ClassCastException: androidx.gridlayout.widget.GridLayout无法转换为 android.widget.GridLayout",在mainActivity.java中
"Caused by: java.lang.ClassCastException: androidx.gridlayout.widget.GridLayout cannot be cast to android.widget.GridLayout", in mainActivity.java
GridLayout mygridLayout = findViewById(R.id.gridLayout);
for(int i=0; i<mygridLayout.getChildCount(); i++)
{
((ImageView) mygridLayout.getChildAt(i)).setImageResource(0);
}
推荐答案
更改
import android.widget.gridLayout
到
import androidx.gridlayout.widget.GridLayout;
您的代码将起作用
这篇关于androidx.gridlayout.widget.GridLayout无法转换为android.widget.GridLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文