我在论坛上看过类似的问题,他们没有帮助解决我的问题。
我正在尝试使用以下代码使用slidingMenu实现:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
slidingMenu = new SlidingMenu(this);
slidingMenu.setMode(SlidingMenu.LEFT);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.setShadowWidthRes(R.dimen.slidingmenu_shadow_width);
slidingMenu.setShadowDrawable(R.drawable.abs__ab_bottom_solid_dark_holo);
slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
slidingMenu.setFadeDegree(0.35f);
slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
slidingMenu.setMenu(R.layout.slidemenu);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// getActionBar().setDisplayHomeAsUpEnabled(true);
// }
}catch(Exception e){
Toast.makeText(this, "SlideMenu malfunction!", Toast.LENGTH_LONG).show();
}
}
但我得到以下错误堆栈:
09-25 02:09:23.042: E/AndroidRuntime(7672): FATAL EXCEPTION: main
09-25 02:09:23.042: E/AndroidRuntime(7672): java.lang.NoClassDefFoundError: android.support.v4.view.ViewConfigurationCompat
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.initCustomViewAbove(CustomViewAbove.java:167)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.<init>(CustomViewAbove.java:157)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.<init>(CustomViewAbove.java:152)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.<init>(SlidingMenu.java:209)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.<init>(SlidingMenu.java:192)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.<init>(SlidingMenu.java:171)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.icerge.revivaltimes.MainActivity.onCreate(MainActivity.java:19)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.os.Looper.loop(Looper.java:144)
09-25 02:09:23.042: E/AndroidRuntime(7672): at android.app.ActivityThread.main(ActivityThread.java:4937)
09-25 02:09:23.042: E/AndroidRuntime(7672): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 02:09:23.042: E/AndroidRuntime(7672): at java.lang.reflect.Method.invoke(Method.java:521)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-25 02:09:23.042: E/AndroidRuntime(7672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-25 02:09:23.042: E/AndroidRuntime(7672): at dalvik.system.NativeStart.main(Native Method)
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.icerge.revivaltimes"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<activity
android:name="com.my.project.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
更新[构建路径错误消息]:
MotionEventCompat cannot be resolved to a variable CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 614 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 600 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 632 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 631 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 636 Java Problem
The constructor SlidingActivityHelper(SlidingFragmentActivity) is undefined SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 21 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 635 Java Problem
MotionEventCompat cannot be resolved to a variable CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 681 Java Problem
MotionEventCompat cannot be resolved to a variable CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 647 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 30 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 11 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 691 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 690 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 20 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 705 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 50 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 759 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 760 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 39 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 736 Java Problem
MotionEventCompat cannot be resolved to a variable CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 758 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 769 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 75 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 780 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 761 Java Problem
MotionEventCompat cannot be resolved to a variable CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 764 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 838 Java Problem
FragmentActivity cannot be resolved to a type SlidingFragmentActivity.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib/app line 149 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 843 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 783 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 837 Java Problem
KeyEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 944 Java Problem
KeyEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 946 Java Problem
MotionEventCompat cannot be resolved CustomViewAbove.java /slidingmenu/src/com/jeremyfeinstein/slidingmenu/lib line 844 Java Problem
答案 0 :(得分:3)
转到工作区中的slidingMenu
库&gt; Properties
&gt; Java Build Path
&gt; Order and Export
标签&gt;确保选中android-support-v4
清理您的项目。这应该是固定的。
编辑:刚刚注意到你在yoru清单中有ActionBar sherlock。在这种情况下,您需要在工作区中为actionbarsherlock库执行相同的步骤。然后,您需要从slidingmenu库中删除android-support-v4
。在actionbarsherlock中添加滑动菜单作为Android库依赖项。然后只需将actionbarsherlock作为Android库添加到您的应用程序中。
您自己的项目应该在其自己的属性中引用ActionBarSherlock,如上所述。 ActionbarSherlock
应该是libs文件夹中android-support-v4.jar
唯一的项目。
最后清洁 - 重建