androidx.drawerlayout.widget.drawerlayout转换为com.google.android.material.navigation.navigationview

pcrecxhr  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(266)

我给我的设计布局下面为您的检查。当我尝试启动应用程序时,它会产生错误并显示消息
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代码供您检查。
向托吉布问好

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题