0

我在论坛上查看了类似的问题,但它们对解决我的问题没有帮助。

我正在尝试使用以下代码使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
4

1 回答 1

3

转到slidingMenu工作区中的库 > Properties> Java Build Path>Order and Export选项卡 > 确保android-support-v4已选中

清理你的项目。这应该是固定的。

编辑:刚刚注意到您在 yoru manifest 中有 ActionBar sherlock。在这种情况下,您需要对工作区中的 actionbarsherlock 库执行相同的步骤。然后你需要android-support-v4从滑动菜单库中删除。在 actionbarsherlock 中添加滑动菜单作为 Android 库依赖项。然后只将 actionbarsherlock 作为 android 库添加到您的应用程序中。

在此处输入图像描述

您自己的项目应该在其自己的属性中引用 ActionBarSherlock,如上所示。ActionbarSherlock应该是android-support-v4.jarlibs 文件夹中唯一的项目。

最后清洁 - 重建

于 2013-09-25T02:23:48.197 回答