Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout

Someone please help me if you have solved this problem before.

I am trying to do something with material design so that the application can run up to 10 APIs. I have no errors in my code, but I keep getting this error.

Android LogCat

06-01 05:05:37.414: E/AndroidRuntime(7043): FATAL EXCEPTION: main
06-01 05:05:37.414: E/AndroidRuntime(7043): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chano8.app/com.chano8.app.MainActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread.access$600(ActivityThread.java:165)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.os.Handler.dispatchMessage(Handler.java:107)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.os.Looper.loop(Looper.java:194)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread.main(ActivityThread.java:5370)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at java.lang.reflect.Method.invoke(Method.java:525)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at dalvik.system.NativeStart.main(Native Method)
06-01 05:05:37.414: E/AndroidRuntime(7043): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.internal.widget.NativeActionModeAwareLayout
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:805)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:324)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at com.chano8.app.MainActivity.onCreate(MainActivity.java:33)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.Activity.performCreate(Activity.java:5228)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
06-01 05:05:37.414: E/AndroidRuntime(7043):     ... 11 more
06-01 05:05:37.414: E/AndroidRuntime(7043): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.widget.NativeActionModeAwareLayout" on path: DexPathList[[zip file "/data/app/com.chano8.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.chano8.app-1, /vendor/lib, /system/lib]]
06-01 05:05:37.414: E/AndroidRuntime(7043):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
06-01 05:05:37.414: E/AndroidRuntime(7043):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-01 05:05:37.414: E/AndroidRuntime(7043):     ... 24 more

      

Below is my code which breaks down according to the above Logcat. MainActivity.java

private static String TAG = MainActivity.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     mToolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        drawerFragment = (FragmentDrawer)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
        drawerFragment.setDrawerListener(this);

        // display the first navigation drawer view on app launch
        displayView(0);

}

      

FragmentDrawer.java

This is the class that draws the menu I want.

private static String TAG = FragmentDrawer.class.getSimpleName();

private RecyclerView recyclerView;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private NavigationDrawerAdapter adapter;
private View containerView;
private static String[] titles = null;
private FragmentDrawerListener drawerListener;

public FragmentDrawer() {

}

public void setDrawerListener(FragmentDrawerListener listener) {
    this.drawerListener = listener;
}

public static List<NavDrawerItem> getData() {
    List<NavDrawerItem> data = new ArrayList<>();


    // preparing navigation drawer items
    for (int i = 0; i < titles.length; i++) {
        NavDrawerItem navItem = new NavDrawerItem();
        navItem.setTitle(titles[i]);
        data.add(navItem);
    }
    return data;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // drawer labels
    titles = getActivity().getResources().getStringArray(R.array.nav_drawer_labels);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflating view layout
    View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
    recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);

    adapter = new NavigationDrawerAdapter(getActivity(), getData());
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener() {
        @Override
        public void onClick(View view, int position) {
            drawerListener.onDrawerItemSelected(view, position);
            mDrawerLayout.closeDrawer(containerView);
        }

        @Override
        public void onLongClick(View view, int position) {

        }
    }));

    return layout;
}

@SuppressLint("NewApi")
public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) {
    containerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActivity().invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            getActivity().invalidateOptionsMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            toolbar.setAlpha(1 - slideOffset / 2);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

}

public static interface ClickListener {
    public void onClick(View view, int position);

    public void onLongClick(View view, int position);
}

static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

    private GestureDetector gestureDetector;
    private ClickListener clickListener;

    @SuppressLint("NewApi")
    public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
        this.clickListener = clickListener;
        gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }

            @Override
            public void onLongPress(MotionEvent e) {
                View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                if (child != null && clickListener != null) {
                    clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                }
            }
        });
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

        View child = rv.findChildViewUnder(e.getX(), e.getY());
        if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
            clickListener.onClick(child, rv.getChildPosition(child));
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean arg0) {
        // TODO Auto-generated method stub

    }
}

public interface FragmentDrawerListener {
    public void onDrawerItemSelected(View view, int position);
}

      

Thank!

+3


source to share


3 answers


create a new project, set MIN target id to 10, appcompat_v7 library will be automatically generated and then add appcompat_v7 as a library in your project.



I used V7 import library, there were the same errors as yours, I decided to use above method.

+2


source


I added the file to my project. it works!,

NativeActionModeAwareLayout.java on AOSP



package android.support.v7.internal.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.View;

/**
 * @hide
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class NativeActionModeAwareLayout extends ContentFrameLayout {

    private OnActionModeForChildListener mActionModeForChildListener;

    public NativeActionModeAwareLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setActionModeForChildListener(OnActionModeForChildListener listener) {
        mActionModeForChildListener = listener;
    }

    public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) {
        if (mActionModeForChildListener != null) {
            return mActionModeForChildListener.startActionModeForChild(originalView, callback);
        }
        return super.startActionModeForChild(originalView, callback);
    }

    /**
     * @hide
     */
    public interface OnActionModeForChildListener {
        ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback);
    }
}

      

+1


source


The problem is in the v7 support lib - NativeActionModeAwareLayout is in version 22.1.1 but not in newer version 22.2.0. Download the "support repository" from SDK manager where all v7 versions support lib.

0


source







All Articles