java - androidx.drawerlayout.widget.DrawerLayout 无法转换为 com.google.android.material.navigation.NavigationView
问题描述
我在下面给出我的设计布局供您检查。当我尝试启动应用程序时,它会产生错误并显示消息
java.lang.ClassCastException:androidx.drawerlayout.widget.DrawerLayout 无法转换为 com.google.android.material.navigation.NavigationView
main.activity.xml
<?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/drawableLayoutId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ModuleActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:background="#F0F8F7" />
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationViewId"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawable_menu_header"
app:menu="@menu/drawable_menu_items">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp"
android:gravity="center"
android:padding="10dp"
android:text="https://www.stieschool.com"
android:textColor="#05156E" />
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
活动.java
package com.stieschool.addressguide;
import android.os.Bundle;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.navigation.NavigationView;
import java.util.ArrayList;
import java.util.List;
public class ModuleActivity extends AppCompatActivity {
Toolbar toolbar;
List<ModuleProperty> modules;
ModuleRecycleViewAdapter adapter;
RecyclerView recyclerView;
DrawerLayout drawerLayout;
NavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_module);
toolbar = findViewById(R.id.toolBarId);
setSupportActionBar(toolbar);
drawerLayout =(DrawerLayout) findViewById(R.id.drawableLayoutId);
navigationView =(NavigationView) findViewById(R.id.drawableLayoutId);
AppUpdateChecker appUpdateChecker=new AppUpdateChecker(this);
appUpdateChecker.checkForUpdate(true);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.drawer_navigation_open,R.string.drawer_navigation_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
modules=new ArrayList<>();
modules.add(new ModuleProperty("মন্ত্রণালয়",R.drawable.module_ministry));
modules.add(new ModuleProperty("হাসপাতাল",R.drawable.module_hospital));
modules.add(new ModuleProperty("বিশ্ববিদ্যালয় ",R.drawable.module_university));
modules.add(new ModuleProperty("শপিং সেন্টার",R.drawable.module_shopping_center));
modules.add(new ModuleProperty("পার্ক",R.drawable.module_park));
modules.add(new ModuleProperty("চিড়িয়াখানা ",R.drawable.module_zoo));
modules.add(new ModuleProperty("ঐতিহাসিক স্থান",R.drawable.module_historial_place));
modules.add(new ModuleProperty("সমুদ্র সৈকত",R.drawable.module_sea_beach));
modules.add(new ModuleProperty("বন-পাহাড়",R.drawable.module_forest));
modules.add(new ModuleProperty("পাহাড়ি ঝর্ণা",R.drawable.module_fountain));
modules.add(new ModuleProperty("কমিউনিটি সেন্টার",R.drawable.module_community_center));
modules.add(new ModuleProperty("পোস্ট অফিস",R.drawable.module_postoffice));
modules.add(new ModuleProperty("কুরিয়ার সার্ভিস",R.drawable.module_curiar_service));
modules.add(new ModuleProperty("আবাসিক হোটেল",R.drawable.module_abasik_hotel));
modules.add(new ModuleProperty("রেস্টুরেন্ট",R.drawable.module_resturant));
recyclerView=findViewById(R.id.recyclerViewId);
adapter=new ModuleRecycleViewAdapter(this,modules);
recyclerView.setLayoutManager(new GridLayoutManager(this,3));
recyclerView.setAdapter(adapter);
}
}
我已共享Java 代码供您检查。
问候托吉布
解决方案
推荐阅读
- javascript - 是否可以在 babel 7 上解构导入?
- salesforce - 在 Visualforce 中,“reRender”刷新部分后“rendered”是否重新执行?
- php - 如何让 CakePHP 加载我的
/src 目录而不是 vendor/maiconpinto/cakephp-adminlte-theme/src - c# - CSV 到对象列表
- python - 是否可以在 Numpy 矢量化广播操作期间访问当前索引?
- ios - tableView 编辑模式删除按钮(减号)没有响应点击 - 我该如何解决这个问题?
- php - 如何将查询字符串添加到 Laravel 视图
- swift - 如何在两个“地方”获取 Firebase 数据?
- location - 切换 IsFloat 时,QDockWidget 不记得浮动大小和位置
- scala - 如果找不到匹配,则将 findFirstMatchIn 设置为忽略行-spark-scala