其他分享
首页 > 其他分享> > 运行时异常:错误膨胀类android.support.v4.widget.DrawerLayout

运行时异常:错误膨胀类android.support.v4.widget.DrawerLayout

作者:互联网

我得到一个错误膨胀类android.support.v4.widget.DrawerLayout.I我发布了以下编码和相关屏幕截图中的详细说明.

堆栈跟踪:

11-04 07:35:04.404: E/AndroidRuntime(1427): FATAL EXCEPTION: main
11-04 07:35:04.404: E/AndroidRuntime(1427): Process: com.example.steve, PID: 1427
11-04 07:35:04.404: E/AndroidRuntime(1427): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.steve/com.example.steve.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.os.Looper.loop(Looper.java:136)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.main(ActivityThread.java:5017)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.reflect.Method.invokeNative(Native Method)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.reflect.Method.invoke(Method.java:515)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at dalvik.system.NativeStart.main(Native Method)
11-04 07:35:04.404: E/AndroidRuntime(1427): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Activity.setContentView(Activity.java:1929)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.qrme.quranmadeeasy.ChapterActivity.onCreate(ChapterActivity.java:91)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Activity.performCreate(Activity.java:5231)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-04 07:35:04.404: E/AndroidRuntime(1427):     ... 11 more
11-04 07:35:04.404: E/AndroidRuntime(1427): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.widget.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.qrme.quranmadeeasy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.qrme.quranmadeeasy-2, /system/lib]]
11-04 07:35:04.404: E/AndroidRuntime(1427):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
11-04 07:35:04.404: E/AndroidRuntime(1427):     ... 20 more

ChapterActivity.java:

package com.example.steve;

import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;

public class MainActivity extends Activity implements OnItemClickListener {

RelativeLayout relativelayoutContainer;
    TextView txtHeading;
    ListView listChapter;
    ListView listSlider;
    ImageView imgBanner;

@SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.activity_main); --->Error line no.91
        initialize();
     }
     private void initialize() {


    relativelayoutContainer = (RelativeLayout) findViewById(R.id.container);
    txtHeading = (TextView) findViewById(R.id.textviewHeading);
    listChapter = (ListView) findViewById(R.id.listviewChapters);
    imgBanner = (ImageView) findViewById(R.id.imageviewBanner);
    listSlider = (ListView) findViewById(R.id.list_slidermenu);

    // Setting font color and size
    Resources resources = ChapterActivity.this.getResources();
     }

    private void displayView(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new FindPeopleFragment();
            break;
        case 2:
            fragment = new PhotosFragment();
            break;

        default:
            break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.frame_container, fragment).commit();

            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(navMenuTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            // error in creating fragment
            Log.e("MainActivity", "Error in creating fragment");
        }
    }
  }

activity_main.xml中:

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

     <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"layout_width="wrap_content"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textviewHeading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:fontFamily="fonts/Dosis.otf"
            android:text="@string/heading_chapter"
            android:textSize="25sp"
            android:visibility="gone" />

        <ListView
            android:id="@+id/listviewChapters"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/imageviewBanner"
            android:layout_below="@+id/textviewHeading"
            android:layout_marginTop="5dp" />
        </ListView>

        <ImageView
            android:id="@+id/imageviewBanner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/banner"
            android:visibility="invisible" />
    </RelativeLayout>


    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
    android:background="@color/list_background"
    android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

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

如果我单击图形布局我在下面得到这个例外:

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.v4.widget.DrawerLayout (Open Class, Show Error Log)

然后在Java Build path-> libraries中

然后在Java Build path – > order and export:

在上面的截图中,如果我检查android.support.v4.jar,我在控制台中收到以下Multiple Dex错误:

[2014-11-04 18:35:30 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
[2014-11-04 18:35:30 - main-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

解决方法:

只需检查android版本和支持lib复选框,它将解决您的问题.

标签:android,executable-jar,navigation-drawer,jar
来源: https://codeday.me/bug/20190716/1476853.html