#android #android-layout #android-fragments
Вопрос:
Получение ошибки, как показано ниже, что мне следует сделать, чтобы устранить эту ошибку.
1617299449.374 31040-31040 E/ncaughtExceptionHandler: Uncaught exception in app
android.view.InflateException: Binary XML file line #5: Binary XML file line #5: Error inflating class layout
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class layout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.layout" on path: DexPathList[[zip file "/data/app/xxx==/base.apk"],nativeLibraryDirectories=[/data/app/xxx==/lib/arm64, /data/app/xxx==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
DiscFragment.java :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
container.removeAllViews();
View rootView = inflater.inflate(getFragmentLayout(), container, false);
ButterKnife.bind(this, rootView);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
xView = ViewModelProviders.of(this, xViewModelFactory).get(ViewModel.class);
xView.getViewModelState().observe(getActivity(), this);
}
disc.xml :
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="discover"
type="xx.ViewModel" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@ id/disc_dis"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_peek_height"
android:background="@{discover.isEnabled ? @drawable/corner_dark : @drawable/corner_light}"
android:orientation="vertical">
<TextView
android:id="@ id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/to"
android:textAlignment="center"
android:textColor="@color/light_gray_color"
android:textSize="@dimen/pd"
android:visibility="gone"
android:textStyle="bold" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/disys"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:listitem="@layout/item_disy_item" />
<ProgressBar
android:id="@ id/disc"
style="?android:attr/progressBarStyleSmall"
android:layout_width="@dimen/progress_bar"
android:layout_height="@dimen/progress_bar"
android:layout_gravity="center"
android:layout_marginTop="@dimen/text_width"
android:indeterminate="true"
android:progressBackgroundTint="@color/background_color"
android:progressTint="@color/progressbar_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.474"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.326" />
<TextView
android:id="@ id/state_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/pd6"
android:gravity="center"
android:paddingStart="@dimen/element_margin"
android:paddingEnd="@dimen/element_margin"
android:text="@string/progress_message"
android:textColor="@{discover.isEnabled ? @color/text_white : @color/text_black_color}"
android:textSize="@dimen/size"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@ id/disc" />
<androidx.appcompat.widget.AppCompatButton
android:id="@ id/btn_error_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/pd12"
android:background="@color/action_btn_background"
android:padding="@dimen/action_btn_padding"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@ id/state_message"
tools:text="@string/expo_turn_bluetooth_on_label" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
<color name="text_white">#FFFFFFFF</color>
<color name="text_black_color">#272626</color>
corner_dark.xml :
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
<solid android:color="@color/darktheme"></solid>
<size android:height="48dp"/>
<padding android:left="4dp" android:top="10dp" android:right="4dp" android:bottom="4dp" />
</shape>
corner_light.xml :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="12dp"
android:topRightRadius="12dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
<solid android:color="@color/white"></solid>
<size android:height="48dp"/>
<padding android:left="4dp" android:top="10dp" android:right="4dp" android:bottom="4dp" />
</shape>
Комментарии:
1. Вы включили привязку данных в
build.gradle
файле вашего модуля?2. Да . Привязка данных { включено = верно }
3. Хорошо, тогда почему вы используете
inflate()
на аLayoutInflater
? Разве вы не должны использовать сгенерированный класс привязки как для раздувания макета, так и для замены ножа для масла?4. Что это
getFragmentLayout()
?5. @Переопределить защищенный int getFragmentLayout() { вернуть R. layout.disc; }