I just migrate to androidx and I got and error like this
androidx.constraintlayout.widget.Guideline cannot be cast to android.view.ViewGroup
It's working fine before I migrate my code to androidx.
I already check some solution about this casting problem, but mostly they have a small mistake like casting a layout inside the button. And I already did some research and got a conclusion that this error showing because the androidx Guideline not a child of ViewGroup. But I can't find the solution yet for this one.
I include my xml and java code below
SettingAccActivity.java
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContext(this);
updateSharedPref(PreferenceConnector.ACTIVITY, this.getClass().getSimpleName());
super.onCreate(savedInstanceState);
FrameLayout contentFrameLayout = findViewById(R.id.frame_content);
LayoutInflater inflater = (LayoutInflater) this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
inflater.inflate(R.layout.activity_settings_acc, contentFrameLayout);
... }
Note : error is on inflater.inflate(R.layout.activity_settings_acc, contentFrameLayout);
activity_base.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
... />
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/layout_drawer"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/light_gray"
app:layout_constraintBottom_toTopOf="@id/layout_bottom_navi"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_main">
<FrameLayout
android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
... />
</androidx.drawerlayout.widget.DrawerLayout>
<include
... />
</androidx.constraintlayout.widget.ConstraintLayout>
activity_setting_acc.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_gray">
<include
... />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_row_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_tiny"
android:background="@color/white"
android:paddingTop="@dimen/padding_normal"
android:paddingRight="@dimen/padding_normal"
android:paddingBottom="@dimen/padding_normal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header_title">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guide_img_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.12" />
<ImageView
android:id="@+id/img_remember_pass"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintLeft_toLeftOf="@id/guide_img_password"
app:layout_constraintRight_toRightOf="@id/guide_img_password"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_remembermypasword_new" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
...
</androidx.constraintlayout.widget.ConstraintLayout>
Any suggestion / answer is a great help for me.
Thanks before.
I already find the solution.
When I adjust the layout from android
to androidx
there's a wrong update.
I change the old ConstraintLayout
to Guideline