我正在使用androidx,并且经常收到此错误,但我无法调试该错误。我正在复制必要的代码并寻求帮助以解决该错误。我看到了其他相关的错误,并且尝试查找错误的xml属性,但是一切似乎正确。
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2530)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2610)
at android.app.ActivityThread.access$800 (ActivityThread.java:179)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1471)
at android.os.Handler.dispatchMessage (Handler.java:111)
at android.os.Looper.loop (Looper.java:194)
at android.app.ActivityThread.main (ActivityThread.java:5646)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createView (LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:809)
at android.view.LayoutInflater.inflate (LayoutInflater.java:504)
at android.view.LayoutInflater.inflate (LayoutInflater.java:414)
at android.view.LayoutInflater.inflate (LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView (AppCompatActivity.java:161)
at com.khan.mymoviescenter.free.MainActivity.onCreate (MainActivity.java:98)
at android.app.Activity.performCreate (Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2477)
Caused by: java.lang.reflect.InvocationTargetException:
at java.lang.reflect.Constructor.newInstance (Native Method)
at java.lang.reflect.Constructor.newInstance (Constructor.java:288)
at android.view.LayoutInflater.createView (LayoutInflater.java:607)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.getValue (Resources.java:1512)
at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates (ResourceManagerInternal.java:252)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable (ResourceManagerInternal.java:139)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable (ResourceManagerInternal.java:132)
at androidx.appcompat.content.res.AppCompatResources.getDrawable (AppCompatResources.java:104)
at androidx.appcompat.view.menu.MenuItemImpl.getIcon (MenuItemImpl.java:505)
at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems (NavigationMenuPresenter.java:585)
at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.update (NavigationMenuPresenter.java:546)
at com.google.android.material.internal.NavigationMenuPresenter.updateMenuView (NavigationMenuPresenter.java:128)
at com.google.android.material.navigation.NavigationView.inflateMenu (NavigationView.java:362)
at com.google.android.material.navigation.NavigationView.<init> (NavigationView.java:228)
at com.google.android.material.navigation.NavigationView.<init> (NavigationView.java:117)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabMode="scrollable"
app:tabGravity="fill"
app:tabIndicatorHeight="3dp"
app:tabIndicatorGravity="bottom" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/app_bar_layout">
</androidx.viewpager.widget.ViewPager>
</RelativeLayout>
<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/header"
app:menu="@menu/main" />
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="horizontal"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentBottom="true"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
app:srcCompat="@drawable/logo"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/inapp_purchases">
<menu>
<item
android:id="@+id/buy_products"
android:icon="@drawable/ic_shopping_cart_black_24dp"
android:title="@string/Buy_Products"
app:actionLayout="@layout/navigation_item_layout"/>
</menu>
</item>
<item android:title="@string/Manage_Database">
<menu>
<item
android:id="@+id/import_export"
android:icon="@drawable/ic_import_export_black_24dp"
android:title="@string/Import_Export"
app:actionLayout="@layout/navigation_item_layout" />
<item
android:id="@+id/my_database"
android:icon="@drawable/database"
android:title="@string/My_Database"/>
<item
android:id="@+id/search_database"
android:icon="@drawable/searchglass"
android:title="@string/Search_Database"
app:actionLayout="@layout/navigation_item_layout"/>
</menu>
</item>
<item android:title="@string/Search_Online">
<menu>
<item
android:id="@+id/search_movies"
android:icon="@drawable/ic_local_movies_black_24dp"
android:title="@string/Search_Movies"
app:actionLayout="@layout/navigation_item_layout" />
</menu>
</item>
<group android:checkableBehavior="single"
android:id="@+id/group_settings">
<item
android:id="@+id/settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/Settings" />
</group>
<item
android:id="@+id/more"
android:icon="@drawable/ic_more_horiz_black_24dp"
android:title="@string/More"
app:actionLayout="@layout/navigation_item_layout" />
<item
android:id="@+id/close"
android:icon="@drawable/ic_exit_to_app_black_24dp"
android:title="@string/Close" />
</menu>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("My App");
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("One"));
tabLayout.addTab(tabLayout.newTab().setText("Two");
tabLayout.addTab(tabLayout.newTab().setText("Three"));
viewPager = (ViewPager) findViewById(R.id.view_pager);
adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setItemIconTintList(null);
assert navigationView != null;
navigationView.setNavigationItemSelectedListener(this);
}