简体   繁体   中英

Could not find class 'android.support.v4.widget.DrawerLayout$1', referenced from method android.support.v4.widget.DrawerLayout

I am facing strange issue in my application. My minSdkVersion is 16. My application is working fine in android lollipop and above device but not working in android 4.1 and 4.4. I am getting error called

Could not find class 'android.support.v4.widget.DrawerLayout$1', referenced from method android.support.v4.widget.DrawerLayout.<init>

My OnCreate code is like below

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /*StartAppSDK.init(this, "207409614", false);
        StartAppAd.disableSplash();
        StartAppAd.enableAutoInterstitial();
        StartAppAd.setAutoInterstitialPreferences(
                new AutoInterstitialPreferences()
                        .setSecondsBetweenAds(60)
                        .setActivitiesBetweenAds(3)
        );*/
        setContentView(R.layout.activity_home_grid);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);

        toggle.syncState();
        setupGridAdapter();

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this , this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        nameView = (TextView) findViewById(R.id.textNavQuotes);
        signInView = (TextView) findViewById(R.id.btnSignIn);
        signInView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (signInView.getText().toString().equalsIgnoreCase("Sign in")) {
                    signIn();
                } else {
                    signOut();
                }

            }
        });
        userPhotoView = (ImageView) findViewById(R.id.imageView);
        userPhotoViewNew = (CircleImageView) findViewById(R.id.imageviewnew);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(HomeActivity.this);
        String userName = preferences.getString("userName", "");
        String userPhotoUriString = preferences.getString("userPhotoUrl", "");
        if (!userName.isEmpty()) {
            nameView.setText(userName);
            userPhotoView.setVisibility(View.GONE);
            Glide.with(HomeActivity.this)
                    .load(Uri.parse(userPhotoUriString))
                    .apply(new RequestOptions()
                            .centerCrop()
                            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                            .dontAnimate()
                            .dontTransform())
                    .into(userPhotoViewNew);

            userPhotoViewNew.setVisibility(View.VISIBLE);
            signInView.setText("Sign out");
        }
        pager = (ViewPager) findViewById(R.id.pager);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(pager);

        setupViewPager();
    }

and Related XML is like below

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/activity_home_tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="?attr/dark_color"
        android:orientation="vertical">


        <include
            layout="@layout/nav_header_home"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <GridView
            android:id="@+id/gridMenu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:numColumns="2"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp">

        </GridView>


    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

My complete log of error is like below

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.home/com.example.home.material.HomeActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:136)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                                                  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
                                                                                  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                                                                                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:816)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                  at com.example.home.material.HomeActivity.onCreate(HomeActivity.java:87)
                                                                                  at android.app.Activity.performCreate(Activity.java:5231)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: java.lang.reflect.InvocationTargetException
                                                                                  at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                                                  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                                                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:816) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                                  at com.example.home.material.HomeActivity.onCreate(HomeActivity.java:87) 
                                                                                  at android.app.Activity.performCreate(Activity.java:5231) 
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/side_nav_bar.xml from drawable resource ID #0x7f020312
                                                                                  at android.content.res.Resources.loadDrawable(Resources.java:2096)
                                                                                  at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                  at android.view.View.<init>(View.java:3554)
                                                                                  at android.view.ViewGroup.<init>(ViewGroup.java:470)
                                                                                  at android.widget.LinearLayout.<init>(LinearLayout.java:176)
                                                                                  at android.widget.LinearLayout.<init>(LinearLayout.java:172)
                                                                                  at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                                  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                                  at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:816) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                                  at com.example.home.material.HomeActivity.onCreate(HomeActivity.java:87) 
                                                                                  at android.app.Activity.performCreate(Activity.java:5231) 
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
                                                                                  at android.content.res.TypedArray.getColor(TypedArray.java:327)
                                                                                  at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:871)
                                                                                  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
                                                                                  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
                                                                                  at android.content.res.Resources.loadDrawable(Resources.java:2092)
                                                                                  at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                                                                                  at android.view.View.<init>(View.java:3554) 
                                                                                  at android.view.ViewGroup.<init>(ViewGroup.java:470) 
                                                                                  at android.widget.LinearLayout.<init>(LinearLayout.java:176) 
                                                                                  at android.widget.LinearLayout.<init>(LinearLayout.java:172) 
                                                                                  at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                                  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                                  at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                                  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                                                                                  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:816) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                                  at com.example.home.material.HomeActivity.onCreate(HomeActivity.java:87) 
                                                                                  at android.app.Activity.performCreate(Activity.java:5231) 
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 

Let me know if someone can help me for solve this issue. Thanks

Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/side_nav_bar.xml from drawable resource ID #0x7f020312

Have you checked that you have right resources in the drawable-xhdpi-v4 folder

Your LinearLayout is failing to open the color attribute.

android:background="?attr/dark_color"

You can try to remove it, or use @color/dark_color , depending on where you get that value from.

i got the same error in huawei mate 7(android 4.4.2).

and i slove it when i add <uses-permission android:name="android.permission.GET_TASKS" /> in AndroidManifest .

this permission is mean Checks for usages of deprecated classes and methods in XML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM