Сама ошибка
Caused by: android.view.InflateException: Binary XML file line #14 in com.buratinoapps.anekdoty:layout/activity_main: Binary XML file line #45 in com.buratinoapps.anekdoty:layout/content_main: Error inflating class fragment
Мой активити
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private AdView adView;
private AppBarConfiguration mAppBarConfiguration;
private MyAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
// RecyclerView
RecyclerView mRecyclerView = findViewById(R.id.recyclerView);
// Set its Properties
//grid view with 2 columns in each row
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
// Adapter
mAdapter = new MyAdapter(this, getModels());
mRecyclerView.setAdapter(mAdapter);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
private ArrayList<Model> getModels() {
ArrayList<Model> models = new ArrayList<>();
Model p;
// Create an items for recycler view below
p = new Model();
p.setTitle("Good Morning");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Good Night");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Love");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Romantics");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Couple");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Valentine Day");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Friendship");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Birthday");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Funny");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Best Wishes");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("G O D");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
p = new Model();
p.setTitle("Attitude");
p.setImage(R.drawable.ic_baseline_right);
models.add(p);
return models;
}
private void layoutAnimation(RecyclerView recyclerView) {
Context context = recyclerView.getContext();
LayoutAnimationController layoutAnimationController =
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_slide_right);
recyclerView.setLayoutAnimation(layoutAnimationController);
recyclerView.getAdapter().notifyDataSetChanged();
recyclerView.scheduleLayoutAnimation();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return false;
}
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("EXIT");
builder.setMessage("Are You Sure Want to Exit?")
.setNegativeButton("No", null)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finishAffinity();
}
}).show();
}
}
Разметка
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>