0

为什么此代码无法访问,我该如何解决?

  public void draggingEvent() {
  image15(); 
  final int thisLetter = currentLetter;
  mImageView15.getDrawable();

  mImageView15 = (ImageView) findViewById(R.id.imageView15);
  mImageView15.setOnDragListener(new OnDragListener() {


    public boolean onDrag(View v, DragEvent de) {
        // TODO Auto-generated method stub
        final int action = de.getAction();
        switch(action) {

        case DragEvent.ACTION_DRAG_STARTED:

            if (de.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            v.invalidate();


            return (true);
            }


            break;

        case DragEvent.ACTION_DRAG_ENTERED:
            v.invalidate();
            return (true);

            break;  //un reachable here
        case DragEvent.ACTION_DRAG_LOCATION:
            //ignore even for now
            if (de.getX() == 250 && de.getY() == 195) {
                mImageView17.setImageResource(thisLetter);
                v.invalidate();
            return (true);
            }
            if (de.getX() == 300 && de.getY() == 195) {
                mImageView17.setImageResource(thisLetter);
            return (true);
            } 
            break;// here
        case DragEvent.ACTION_DRAG_EXITED:
            de.getResult();
            break; //here
        case DragEvent.ACTION_DROP:
            ClipData.Item item = de.getClipData().getItemAt(thisLetter);
            v.invalidate();
            return (true);

            break; // here
        case DragEvent.ACTION_DRAG_ENDED:
            v.invalidate();

            if (de.getResult()) {
                Log.e("it worked", "worked");
            } else {
                Log.e("failed", "sorry failed drag and drop");
            return (true);
            }
            break; //here

            default: 
                Log.e("Drag drop", "Failed to find area");
            break; // and here



    };
    return false;
    };

  });
4

3 回答 3

2

一般情况下,return 语句后面的语句Java不会被执行。

几乎是正确的;有一个重要的例外有助于程序的稳定性,那就是finally块。例如

try {
    doSomething();
    return;
} finally {
    cleanUp();
}

该函数cleanUp() 被执行。

于 2013-05-21T12:34:36.753 回答
2

return 后不能执行任何Java语句:

return (true);
break;  //un reachable here

只是有return声明。(你有两次这样的事件)

于 2013-05-21T12:25:57.247 回答
1

因为你return (true)在你之前做breakbreak将永远不会被调用。

于 2013-05-21T12:25:11.343 回答