Home>

I am immediately creating a web application using ViewPager and WebView.
An error occurred in a specific API during verification this time, and I'm in trouble because I don't understand the details of the error.

An error has occurred in API21&22.
(No error in other environments)

targetSdkVersion 29
minSdkVersion 21

Although it is an error content, it is an error when xml is read for the first time with inflater.inflate in onCreateView.
The program in question is below.

RedWebView.java

View redView;
@Override
    public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Do not discard the fragment when regenerating the activity.
        setRetainInstance (true);
        // Instantiate the original activity
        View wv = inflater.inflate (R.layout.activity_main, container, false);
        // Do not enter once generated to prevent initialization
        if (redView == null) {
            // Here is an error error
            try {
                redView = inflater.inflate (R.layout.redwebview, container, false);
            } catch (InflateException e) {
                Log.d ("Error 1", "Reason for reading failure" + e);
            }
        }
        // Top logo declaration
        logo_top = (ImageButton) wv.findViewById (R.id.logo_top);
        // SwipeRefreshLayout settings
        mSwipeRefreshLayout = (SwipeRefreshLayout) redView.findViewById (R.id.swipe_refresh);
        mSwipeRefreshLayout.setColorSchemeResources (R.color.red_main_color);
        mSwipeRefreshLayout.setOnRefreshListener (mOnRefreshListener);
        // get dp units
        scale = getResources (). getDisplayMetrics (). density;
        // Set the margin to 20dp
        margins = (int) (20 * scale);
        // Instantiate progress bar
        progressBar = redView.findViewById (R.id.progressBar);
        // Set the value of the progress bar MAX
        progressBar.setMax (100);
        // Progress value of progress bar
        progressBar.setProgress (0);
        return redView;
    }


activity_main.xml

<? xml version = "1.0" encoding = "utf-8"?>


    
        <com.google.android.material.appbar.AppBarLayout
            android: layout_height = "wrap_content"
            android: layout_width = "match_parent"
            android: theme = "@ style/AppTheme.AppBarOverlay">
            

                
            </androidx.appcompat.widget.Toolbar>
            <com.google.android.material.tabs.TabLayout
                android: id = "@ + id/tabs"
                android: layout_width = "match_parent"
                android: layout_height = "35dp"
                android: background = "@ color/white"
                android: paddingTop = "0dp"
                android: paddingBottom = "0dp"
                android: paddingLeft = "0dp"
                android: paddingRight = "0dp"
                android: state_selected = "true"
                app: tabBackground = "@ drawable/tab_color_selector"
                app: tabGravity = "fill"
                app: tabMaxWidth = "0dp"
                app: tabMode = "fixed"
                app: tabTextAppearance = "@ style/TabText" />

        </com.google.android.material.appbar.AppBarLayout>
        // ViewPager is here
        

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android: id = "@ + id/bottom_navigation"
            android: layout_width = "match_parent"
            android: layout_height = "@ dimen/design_bottom_navigation_height"
            android: background = "@ color/white"
            android: layout_gravity = "bottom"
            app: itemHorizontalTranslationEnabled = "false"
            app: labelVisibilityMode = "labeled"app: layout_constraintBottom_toBottomOf = "parent"
            app: layout_constraintLeft_toLeftOf = "parent"
            app: layout_constraintRight_toRightOf = "parent"
            app: menu = "@ menu/bottom_navigation_menu" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android: id = "@ + id/nav_view"
        android: layout_width = "240dp"
        android: layout_height = "match_parent"
        android: layout_gravity = "end"
        android: fitsSystemWindows = "true"
        app: menu = "@ menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

redwebview.xml

<? xml version = "1.0" encoding = "utf-8"?>
<FrameLayout 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"
    tools: context = ". ui.main.RedWebView">
        
                <RelativeLayout
                    android: layout_width = "wrap_content"
                    android: layout_height = "wrap_content"
                    android: fitsSystemWindows = "true"
                    android: background = "@ color/red_main_color">
                        <ProgressBar
                            android: id = "@ + id/progressBar"
                           
                            android: layout_width = "match_parent"
                            android: layout_height = "25dp"
                            android: layout_alignParentTop = "true"
                            android: layout_centerHorizontal = "true"
                            android: layout_centerVertical = "true"
                            android: layout_marginTop = "-10dp"
                            android: backgroundTintMode = "add"
                            android: indeterminate = "false"
                            android: progressDrawable = "@ drawable/redprogress"
                            tools: visibility = "visible" />
                        // Location where error occurs
                        <Package name.NestedWebView
                            android: id = "@ + id/redWebView"
                            android: layout_width = "match_parent"
                            android: layout_height = "match_parent"
                            android: isScrollContainer = "false"
                            android: layout_marginTop = "5dp" />
                </RelativeLayout>
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
D/Error 1: Reason for reading failure is android.view.InflateException: Binary XML file line # 32: Error inflating class package name.NestedWebView

Additional contents

Since

try is used, go down as it is and an error will occur in SwipeRefreshLayout.
The contents of chach are described above.

Beyond 10,000 characters, fill in below.

  • Answer # 1

    According to the search, API21 ~ 22 [Lollipop, Android5.0 ~ 5.1] (emulator?) WebView seems to have a problem for some time, but I do not know the current correction status today.
    There was a method of downgrading the library and resolving (?) In the comment below.

    android.view.InflateException Error inflating class android.webkit.WebView

Related articles