拖动事件上的NoClassDefFoundError(拖放;拖放)

时间:2012-05-10 09:59:27

标签: android

我尝试将DragListener实现到我的Fragment,但应用程序崩溃并在此行上给我一个NoClassDefFoundError:

findViewById(R.id.my_tab_fragment).setOnDragListener(new MyDragListener());

这是我的代码:

public class MainFragmentActivity extends FragmentActivity {


    @Override    
    protected void onCreate(Bundle bundle) {   

        WWHApplication.getInstance().getJsonDBInstance();
        WWHApplication.checkDB();

        super.onCreate(bundle);
        setContentView(R.layout.main_fragment_activity_drag);

        findViewById(R.id.my_tab_fragment).setOnDragListener(new MyDragListener());


            }


            class MyDragListener implements OnDragListener {
                //Drawable enterShape = getResources().getDrawable(
                    //  R.drawable.shape_droptarget);
                //Drawable normalShape = getResources().getDrawable(R.drawable.shape);

                @Override
                public boolean onDrag(View v, DragEvent event) {
                    switch (event.getAction()) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        // Do nothing
                        break;
                    case DragEvent.ACTION_DRAG_ENTERED:
                        //v.setBackgroundDrawable(enterShape);
                        break;
                    case DragEvent.ACTION_DRAG_EXITED:
                        //v.setBackgroundDrawable(normalShape);
                        break;
                    case DragEvent.ACTION_DROP:
                        // Dropped, reassign View to ViewGroup
                        //View view = (View) event.getLocalState();
                        //ViewGroup owner = (ViewGroup) view.getParent();
                        //owner.removeView(view);
                        //LinearLayout container = (LinearLayout) v;
                        //container.addView(view);
                        //view.setVisibility(View.VISIBLE);
                        break;
                    case DragEvent.ACTION_DRAG_ENDED:
                        //v.setBackgroundDrawable(normalShape);
                    default:
                        break;
                    }
                    return true;
                }
            }
    }

我需要做些什么来修复错误?感谢

1 个答案:

答案 0 :(得分:2)

如果您在设备上运行它,则应检查其API级别。如果它运行2.2.x(API级别8),则不能使用拖放,因为它需要API 11