我在我的项目中使用滑动菜单库它工作得很好,但我从设备上卸载了我的应用程序并通过Eclipse再次安装它。应用程序的大小从7.92 MB减少到6.92 MB。 滑动菜单应出现在Activity中的位置,它不会打开,并且我的logcat中会出现以下错误。
11-17 17:58:52.241: E/AndroidRuntime(4049): FATAL EXCEPTION: main
11-17 17:58:52.241: E/AndroidRuntime(4049): Process: com.example.sayminicabdriver, PID: 4049
11-17 17:58:52.241: E/AndroidRuntime(4049): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sayminicabdriver/mapslider.sliding}: java.lang.NullPointerException
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.os.Handler.dispatchMessage(Handler.java:102)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.os.Looper.loop(Looper.java:136)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread.main(ActivityThread.java:5001)
11-17 17:58:52.241: E/AndroidRuntime(4049): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 17:58:52.241: E/AndroidRuntime(4049): at java.lang.reflect.Method.invoke(Method.java:515)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-17 17:58:52.241: E/AndroidRuntime(4049): at dalvik.system.NativeStart.main(Native Method)
11-17 17:58:52.241: E/AndroidRuntime(4049): Caused by: java.lang.NullPointerException
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.view.ViewGroup.addView(ViewGroup.java:3353)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.view.ViewGroup.addView(ViewGroup.java:3336)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.setContent(CustomViewAbove.java:436)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.setContent(SlidingMenu.java:356)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.attachToActivity(SlidingMenu.java:332)
11-17 17:58:52.241: E/AndroidRuntime(4049): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.attachToActivity(SlidingMenu.java:292)
11-17 17:58:52.241: E/AndroidRuntime(4049): at mapslider.sliding.onCreate(sliding.java:122)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.Activity.performCreate(Activity.java:5231)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-17 17:58:52.241: E/AndroidRuntime(4049): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
11-17 17:58:52.241: E/AndroidRuntime(4049): ... 11 more
之前我的代码运行良好,但突然出现了这个错误。
的
的 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setBehindContentView(R.layout.content_frame);
SlidingMenu menu_bus = new SlidingMenu(this);
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu_bus.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
//firs slide menu, then second
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new MenuFragment()).commit();
getSlidingMenu().setBehindOffset(50);
// getSupportActionBar().setDisplayShowCustomEnabled(true);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSlidingMenu().setSecondaryMenu(R.layout.right_main);
getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
//start fragment for second menu
getSupportFragmentManager()
.beginTransaction()
.add(R.id.right_container, new RightFragment(),"test_bus")
.commit();
Button csButton=(Button)findViewById(R.id.button1);
csButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
getSlidingMenu().showMenu();
}//inside csButton1 onclick listener just need to call
});
// inside csButton onclick listener just need to call slidingMenu.showSecondaryMenu();
Button csButton1=(Button)findViewById(R.id.button2);
csButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
getSlidingMenu().showSecondaryMenu();
}
}) ;
的 提前致谢。
答案 0 :(得分:0)
尝试清理项目并确保使用库(右键单击项目,属性)或java构建路径