this is the error given by android studio when my apps crashes.
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #17: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.example.expensemanager-YyqHD9regFat63AepxJ6Yg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.expensemanager-YyqHD9regFat63AepxJ6Yg==/lib/x86, /system/lib]]
Here is my code:
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = findViewById(R.id.my_toolbar);
toolbar.setTitle("Expense manager");
setSupportActionBar(toolbar);
CoordinatorLayout coordinatorLayout = findViewById(R.id.coordinator);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_cloused);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
NavigationView navView = findViewById(R.id.nav_view);
navView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
drawerLayout.closeDrawer(GravityCompat.END);
} else {
super.onBackPressed();
}
}
public void displaySlectedListener(int itemId) {
Fragment fragment = null;
if (itemId == R.id.dash_board) {
} else if (itemId == R.id.income) {
} else if (itemId == R.id.expense) {
}
if (fragment != null) {
FragmentTransaction FT = getSupportFragmentManager().beginTransaction();
FT.replace(R.id.main_frame, fragment);
FT.commit();
}
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
drawerLayout.closeDrawer(GravityCompat.START);
}
public void setSupportActionBar(Toolbar toolbar) {
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
displaySlectedListener(item.getItemId());
return true;
}
}
add compile 'com.android.support:design:xx.x.x'
to build.gradle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.