滑动菜单问题

时间:2014-02-22 11:45:46

标签: android slidingmenu slidingdrawer sliding

我创建了一个滑动菜单..它工作得很完美,但今天我想添加一个新的块...我做到了,它很完美,但是在创建之后,它出现了一个错误,据说添加了一个超级警告getActionBar().setDisplayHomeAsUpEnabled(true);getActionBar().setHomeButtonEnabled(true); ...我解决了错误,但在此之前应用程序不再正常工作,当我不得不打开滑动活动时,应用程序崩溃了。

这是我的logcat:

02-22 13:39:12.989: E/AndroidRuntime(485): FATAL EXCEPTION: main
02-22 13:39:12.989: E/AndroidRuntime(485): java.lang.NoSuchMethodError: com.orar.cngcnasaud.MainActivity.getActionBar
02-22 13:39:12.989: E/AndroidRuntime(485):  at com.orar.cngcnasaud.MainActivity.onCreate(MainActivity.java:46)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.os.Looper.loop(Looper.java:123)
02-22 13:39:12.989: E/AndroidRuntime(485):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-22 13:39:12.989: E/AndroidRuntime(485):  at java.lang.reflect.Method.invokeNative(Native Method)
02-22 13:39:12.989: E/AndroidRuntime(485):  at java.lang.reflect.Method.invoke(Method.java:521)
02-22 13:39:12.989: E/AndroidRuntime(485):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-22 13:39:12.989: E/AndroidRuntime(485):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-22 13:39:12.989: E/AndroidRuntime(485):  at dalvik.system.NativeStart.main(Native Method)

如果我理解得当,我认为问题出现在onCreate选项中,我写的是2个代码。所以,这里是我的onCreate方法:

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

        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

        // set a custom shadow that overlays the main content when the drawer
        // opens
        mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        _initMenu();
        mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
        mDrawer.setDrawerListener(mDrawerToggle);

    }

非常感谢!

logcat中的错误已经改变:

logcat的:

02-22 12:42:58.730: E/AndroidRuntime(890): FATAL EXCEPTION: main
02-22 12:42:58.730: E/AndroidRuntime(890): android.content.res.Resources$NotFoundException: String resource ID #0x0
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.content.res.Resources.getText(Resources.java:230)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.TextView.setText(TextView.java:3769)
02-22 12:42:58.730: E/AndroidRuntime(890):  at com.orar.cngcnasaud.NsMenuAdapter.getView(NsMenuAdapter.java:108)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.AbsListView.obtainView(AbsListView.java:2159)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.ListView.makeAndAddView(ListView.java:1831)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.ListView.fillDown(ListView.java:674)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.ListView.fillFromTop(ListView.java:735)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.ListView.layoutChildren(ListView.java:1652)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.AbsListView.onLayout(AbsListView.java:1994)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.View.layout(View.java:14008)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.View.layout(View.java:14008)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.View.layout(View.java:14008)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.View.layout(View.java:14008)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.View.layout(View.java:14008)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewGroup.layout(ViewGroup.java:4373)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.Choreographer.doFrame(Choreographer.java:532)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.os.Handler.handleCallback(Handler.java:725)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.os.Looper.loop(Looper.java:137)
02-22 12:42:58.730: E/AndroidRuntime(890):  at android.app.ActivityThread.main(ActivityThread.java:5041)
02-22 12:42:58.730: E/AndroidRuntime(890):  at java.lang.reflect.Method.invokeNative(Native Method)
02-22 12:42:58.730: E/AndroidRuntime(890):  at java.lang.reflect.Method.invoke(Method.java:511)
02-22 12:42:58.730: E/AndroidRuntime(890):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-22 12:42:58.730: E/AndroidRuntime(890):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-22 12:42:58.730: E/AndroidRuntime(890):  at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:1)

如果你的android:minSdkVersion设置为8(API-8),它不提供getActionBar()(仅限API-11)。

如果抑制了lint警告,则不会出现编译时错误。

尝试http://actionbarsherlock.com/ - 向后兼容性有帮助。

如果你想检查, 看看是否有效:

if (android.os.Build.VERSION.SDK_INT >= 11)
    getActionBar().setDisplayHomeAsUpEnabled(true);

更新后的logcat显示标识您的资源ID时出错。

查看是否在传递给适配器的相同布局中有TextView(有问题)。或者检查它的初始化。

答案 1 :(得分:1)

getActionBar()仅在SDK 11之后可用。因此,看起来您使用的是较旧的SDK。