android – 错误膨胀DrawerLayout

android – 错误膨胀DrawerLayout,第1张

概述public class HomeActivity extends Activity {private String[] drawer_options;private ListView mDrawerList;private DrawerLayout mDrawerLayout;private ActionBarDrawerToggle mDrawerToggle;private Cha
public class HomeActivity extends Activity {private String[] drawer_options;private ListVIEw mDrawerList;private DrawerLayout mDrawerLayout;private ActionbarDrawerToggle mDrawerToggle;private CharSequence mDrawerTitle;private CharSequence mTitle;@Suppresslint("NewAPI")@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_home);    mTitle = mDrawerTitle = getTitle();    drawer_options = getResources().getStringArray(R.array.drawer_array);    mDrawerLayout = (DrawerLayout) findVIEwByID(R.ID.drawer_layout);    mDrawerList = (ListVIEw) findVIEwByID(R.ID.left_drawer);    // set a custom shadow that overlays the main content when the drawer opens   mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);    // set up the drawer's List vIEw with items and click Listener    mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_List_item,drawer_options));    mDrawerList.setonItemClickListener(new DrawerItemClickListener());    // enable Actionbar app icon to behave as action to toggle nav drawer    getActionbar().setdisplayHomeAsUpEnabled(true);    getActionbar().setHomebuttonEnabled(true);    // ActionbarDrawerToggle tIEs together the the proper interactions    // between the slIDing drawer and the action bar app icon    mDrawerToggle = new ActionbarDrawerToggle(            this,/* host Activity */            mDrawerLayout,/* DrawerLayout object */            R.drawable.ic_drawer,/* nav drawer image to replace 'Up' caret */            R.string.drawer_open,/* "open drawer" description for accessibility */            R.string.drawer_close  /* "close drawer" description for accessibility */            ) {        public voID onDrawerClosed(VIEw vIEw) {            getActionbar().setTitle(mTitle);            invalIDateOptionsMenu(); // creates call to onPrepareOptionsMenu()        }        public voID onDrawerOpened(VIEw drawerVIEw) {            getActionbar().setTitle(mDrawerTitle);            invalIDateOptionsMenu(); // creates call to onPrepareOptionsMenu()        }    };    mDrawerLayout.setDrawerListener(mDrawerToggle);    if (savedInstanceState == null) {        selectItem(0);    }}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    MenuInflater inflater = getMenuInflater();    inflater.inflate(R.menu.main,menu);    return super.onCreateOptionsMenu(menu);}/* Called whenever we call invalIDateOptionsMenu() */@OverrIDepublic boolean onPrepareOptionsMenu(Menu menu) {    // If the nav drawer is open,hIDe action items related to the content vIEw    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);    menu.findItem(R.ID.ActionItem1).setVisible(!drawerOpen);    return super.onPrepareOptionsMenu(menu);}@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {     // The action bar home/up action should open or close the drawer.     // ActionbarDrawerToggle will take care of this.    if (mDrawerToggle.onoptionsItemSelected(item)) {        return true;    }    // Handle action buttons    switch(item.getItemID()) {    case R.ID.ActionItem1:        // create intent to perform web search for this planet        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);        intent.putExtra(SearchManager.query,getActionbar().getTitle());        // catch event that there's no activity to handle intent        if (intent.resolveActivity(getPackageManager()) != null) {            startActivity(intent);        } else {            Toast.makeText(this,R.string.app_not_available,Toast.LENGTH_LONG).show();        }        return true;    default:        return super.onoptionsItemSelected(item);    }}/* The click Listner for ListVIEw in the navigation drawer */private class DrawerItemClickListener implements ListVIEw.OnItemClickListener {    @OverrIDe    public voID onItemClick(AdapterVIEw<?> parent,VIEw vIEw,int position,long ID) {        selectItem(position);    }}private voID selectItem(int position) {    // update the main content by replacing fragments    Fragment fragment = new PlanetFragment();    Bundle args = new Bundle();    args.putInt(PlanetFragment.ARG_PLANET_NUMBER,position);    fragment.setArguments(args);    FragmentManager fragmentManager = getFragmentManager();    fragmentManager.beginTransaction().replace(R.ID.content_frame,fragment).commit();    // update selected item and Title,then close the drawer    mDrawerList.setItemChecked(position,true);    setTitle(drawer_options[position]);    mDrawerLayout.closeDrawer(mDrawerList);}@OverrIDepublic voID setTitle(CharSequence Title) {    mTitle = Title;    getActionbar().setTitle(mTitle);}@OverrIDeprotected voID onPostCreate(Bundle savedInstanceState) {    super.onPostCreate(savedInstanceState);    // Sync the toggle state after onRestoreInstanceState has occurred.    mDrawerToggle.syncState();}@OverrIDepublic voID onConfigurationChanged(Configuration newConfig) {    super.onConfigurationChanged(newConfig);    // Pass any configuration change to the drawer toggls    mDrawerToggle.onConfigurationChanged(newConfig);}/** * Fragment that appears in the "content_frame" */public static class PlanetFragment extends Fragment {    public static final String ARG_PLANET_NUMBER = "planet_number";    public PlanetFragment() {        // Empty constructor required for fragment subclasses    }    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {        VIEw rootVIEw = inflater.inflate(R.layout.cliq_fragment,container,false);        int i = getArguments().getInt(ARG_PLANET_NUMBER);        String planet = getResources().getStringArray(R.array.drawer_array)[i];        int imageID = getResources().getIDentifIEr(planet.tolowerCase(Locale.getDefault()),"drawable",getActivity().getPackagename());        ((ImageVIEw) rootVIEw.findVIEwByID(R.ID.image)).setimageResource(imageID);        getActivity().setTitle(planet);        return rootVIEw;    }}}

我正在尝试使用intent从另一个活动开始此活动.我不确定是什么错,或者我错过了什么,因为它强制关闭onCreate()我试图从logcat中查找错误,但我没有运气.这是开始此活动时的logcat.

05-20 22:59:27.697: D/memalloc(21948): /dev/pmem: UnmapPing buffer base:0x51d88000 size:4976640 offset:485376005-20 22:59:27.697: D/memalloc(21948): /dev/pmem: UnmapPing buffer base:0x52247000 size:5099520 offset:497664005-20 22:59:27.697: D/memalloc(21948): /dev/pmem: UnmapPing buffer base:0x52724000 size:5222400 offset:509952005-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve virtual method 53: LandroID/support/v4/Widget/DrawerLayout;.closeDrawer (LandroID/vIEw/VIEw;)V05-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve virtual method 50: LandroID/support/v4/app/ActionbarDrawerToggle;.onConfigurationChanged (LandroID/content/res/Configuration;)V05-20 22:59:27.727: E/dalvikvm(21948): Could not find class 'androID.support.v4.Widget.DrawerLayout',referenced from method com.example.facecliq.HomeActivity.onCreate05-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve check-cast 32 (LandroID/support/v4/Widget/DrawerLayout;) in Lcom/example/facecliq/HomeActivity;05-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve virtual method 51: LandroID/support/v4/app/ActionbarDrawerToggle;.onoptionsItemSelected (LandroID/vIEw/MenuItem;)Z05-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve virtual method 52: LandroID/support/v4/app/ActionbarDrawerToggle;.syncState ()V05-20 22:59:27.727: W/dalvikvm(21948): VFY: unable to resolve virtual method 54: LandroID/support/v4/Widget/DrawerLayout;.isDrawerOpen (LandroID/vIEw/VIEw;)Z05-20 22:59:27.727: W/dalvikvm(21948): Unable to resolve superclass of Lcom/example/facecliq/HomeActivity; (30)05-20 22:59:27.737: W/dalvikvm(21948): link of class 'Lcom/example/facecliq/HomeActivity;' Failed05-20 22:59:27.757: W/dalvikvm(21948): threadID=1: thread exiting with uncaught exception (group=0x40a9e1f8)05-20 22:59:27.777: E/AndroIDRuntime(21948): FATAL EXCEPTION: main05-20 22:59:27.777: E/AndroIDRuntime(21948): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.facecliq/com.example.facecliq.HomeActivity}: androID.vIEw.InflateException: Binary XML file line #1: Error inflating class androID.support.v4.Widget.DrawerLayout05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1956)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread.access0(ActivityThread.java:123)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.os.Handler.dispatchMessage(Handler.java:99)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.os.Looper.loop(Looper.java:137)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread.main(ActivityThread.java:4424)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at java.lang.reflect.Method.invokeNative(Native Method)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at java.lang.reflect.Method.invoke(Method.java:511)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:812)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:579)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at dalvik.system.NativeStart.main(Native Method)05-20 22:59:27.777: E/AndroIDRuntime(21948): Caused by: androID.vIEw.InflateException: Binary XML file line #1: Error inflating class androID.support.v4.Widget.DrawerLayout05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:691)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:466)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:396)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:352)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at com.androID.internal.policy.impl.PhoneWindow.setContentVIEw(PhoneWindow.java:251)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.Activity.setContentVIEw(Activity.java:1835)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at com.example.facecliq.HomeActivity.onCreate(HomeActivity.java:40)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.Activity.performCreate(Activity.java:4465)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1920)05-20 22:59:27.777: E/AndroIDRuntime(21948):    ... 11 more05-20 22:59:27.777: E/AndroIDRuntime(21948): Caused by: java.lang.classNotFoundException: androID.support.v4.Widget.DrawerLayout05-20 22:59:27.777: E/AndroIDRuntime(21948):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at java.lang.classLoader.loadClass(ClassLoader.java:501)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at java.lang.classLoader.loadClass(ClassLoader.java:461)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:552)05-20 22:59:27.777: E/AndroIDRuntime(21948):    at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:680)05-20 22:59:27.777: E/AndroIDRuntime(21948):    ... 20 more
解决方法 确保您使用的是包含DrawerLayout和其他相关类的支持库(13)的最新版本.将支持库的.jar复制到项目的/ libs文件夹中.最后,将ADT更新到最新版本. Logcat抱怨

Caused by: androID.vIEw.InflateException: Binary XML file line #1: Error inflating class androID.support.v4.Widget.DrawerLayout 05-20 22:59:27.777: E/AndroIDRuntime(21948): atCould not find class 'androID.support.v4.Widget.DrawerLayout',referenced from method com.example.facecliq.HomeActivity.onCreate
总结

以上是内存溢出为你收集整理的android – 错误膨胀DrawerLayout全部内容,希望文章能够帮你解决android – 错误膨胀DrawerLayout所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1122017.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存