0

所以我使用滑动菜单来创建一个不错的小菜单,但没有片段。有了这个,我已经设置了一个 ListView 来显示我的菜单。尝试使用 onItemClick 这样我就可以切换到下一个活动,但是在运行应用程序时我得到了一个致命的异常。下面是我的代码:

    private void mainMenu() {
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidth(5);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setBehindWidth(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setMenu(R.layout.menu_frame);

    ListView v = (ListView)findViewById(R.id.menu_frame);
    v.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, menu_items));
    v.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
            Log.i(TAG, "HERE");
        }

    });
}

日志猫:

04-26 12:31:54.055: E/AndroidRuntime(26955): FATAL EXCEPTION: main
04-26 12:31:54.055: E/AndroidRuntime(26955): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.naughtydog.blogreader/com.domain.blogreader.MainListActivity}: java.lang.NullPointerException
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.os.Looper.loop(Looper.java:137)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread.main(ActivityThread.java:5041)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at java.lang.reflect.Method.invokeNative(Native Method)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at java.lang.reflect.Method.invoke(Method.java:511)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at dalvik.system.NativeStart.main(Native Method)
04-26 12:31:54.055: E/AndroidRuntime(26955): Caused by: java.lang.NullPointerException
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at com.naughtydog.blogreader.MainListActivity.<init>(MainListActivity.java:53)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at java.lang.Class.newInstanceImpl(Native Method)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at java.lang.Class.newInstance(Class.java:1319)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 12:31:54.055: E/AndroidRuntime(26955):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-26 12:31:54.055: E/AndroidRuntime(26955):    ... 11 more
4

1 回答 1

0

我恢复到上一个​​工作版本,然后重新添加了所有内容,它似乎可以工作。感谢并为浪费时间感到抱歉。

于 2013-04-26T21:37:55.413 回答