Reputation: 187
I keep getting this error. I have tried solutions I could find here on StackOverflow but nothing worked.
This is the error: Error inflating class android.support.design.widget.TabLayout
Here is what I used in dependencies: implementation 'com.android.support:design:29.3.0'
This is how the XML looks:
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
I have tried to create a version-v21 folder and set the theme but the this can't take style as an attribute. Followed this: http://geeksmember.blogspot.com/2015/10/errorerror-inflating-class.html
I have also tried the change the theme in the manifest with a custom made one.
Full activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.android.tourguide.MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I also get an error at line 16 in MainActivity.java: (setContentView)
package com.example.android.tourguide;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
//import android.support.design.widget.TabLayout;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the view pager that will allow the user to swipe between fragments
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
// Create adapter to show the appropriate fragment for each page
SimpleFragmentPagerAdapter adapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager());
// Set the adapter onto the view pager
viewPager.setAdapter(adapter);
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
}
}
Here is the entire logcat:
2019-08-14 21:08:12.864 6000-6000/? I/droid.tourguid: Not late-enabling -Xcheck:jni (already on)
2019-08-14 21:08:12.891 6000-6000/? W/droid.tourguid: Unexpected CPU variant for X86 using defaults: x86
2019-08-14 21:08:13.344 6000-6000/com.example.android.tourguide W/droid.tourguid: JIT profile information will not be recorded: profile file does not exits.
2019-08-14 21:08:13.347 6000-6000/com.example.android.tourguide I/chatty: uid=10089(com.example.android.tourguide) identical 10 lines
2019-08-14 21:08:13.347 6000-6000/com.example.android.tourguide W/droid.tourguid: JIT profile information will not be recorded: profile file does not exits.
2019-08-14 21:08:13.431 6000-6000/com.example.android.tourguide I/InstantRun: starting instant run server: is main process
2019-08-14 21:08:13.659 6000-6000/com.example.android.tourguide W/droid.tourguid: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-08-14 21:08:13.659 6000-6000/com.example.android.tourguide W/droid.tourguid: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-08-14 21:08:13.672 6000-6000/com.example.android.tourguide D/AndroidRuntime: Shutting down VM
2019-08-14 21:08:13.680 6000-6000/com.example.android.tourguide E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.tourguide, PID: 6000
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.tourguide/com.example.android.tourguide.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TabLayout" on path: DexPathList[[zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/base.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_resources_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
2019-08-14 21:08:13.685 6000-6000/com.example.android.tourguide E/AndroidRuntime: at com.example.android.tourguide.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.android.tourguide-Ok8HTD230dRMxKJwA7oooQ==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
... 6 more
2019-08-14 21:08:13.726 6000-6000/com.example.android.tourguide I/Process: Sending signal. PID: 6000 SIG: 9
For more information, ask, please.
Upvotes: 1
Views: 1867
Reputation: 290
Replace
android.support.design.widget.TabLayout
android.support.v4.view.ViewPager
with
com.google.android.material.tabs.TabLayout
androidx.viewpager.widget.ViewPager
add to app.gradle dependencies
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.viewpager:viewpager:1.0.0'
Upvotes: 1
Reputation: 29783
Both of your Layout and Activity should use the matching view. In your activity, you're using the following androidX library:
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
So, you also need to use the same view in your layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.android.tourguide.MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Please be noted, there is no version 29
for the support libraries. The last version is only version 28.0.0
, see the changelog.
Also, see Migrating to AndroidX
Upvotes: 3
Reputation: 1140
You are imported androidx library in activity and using support library in xml. Use support library in activity class.
Upvotes: 2