0

I created an activity which has com.google.android.glass.touchpad.Gesture amongst other imports and it's all fine and running.

Then I needed to manage Gestures, so I imported

import com.google.android.glass.touchpad.GestureDetector` 

and created the proper methods to allow the creation of the GestureDetector

    public class LiveCardMenuActivity extends Activity{

    private GestureDetector mGestureDetector;

public boolean onGenericMotionEvent(MotionEvent event) {
        if (mGestureDetector != null) {
            return mGestureDetector.onMotionEvent(event);
        }
        return false;
    }

private GestureDetector createGestureDetector(Context context){

        GestureDetector gestureDetector = new GestureDetector(context);

        gestureDetector.setBaseListener(new GestureDetector.BaseListener(){

            @Override
            public boolean onGesture(Gesture gesture){
                if(gesture == Gesture.TAP){
                    Log.d("Gesture.TAP","tapped");
                    return true;
                }else if(gesture == Gesture.TWO_TAP){
                    return true;
                }else if(gesture == Gesture.SWIPE_RIGHT){
                    return true;
                }else if(gesture == Gesture.SWIPE_LEFT){
                    return true;
                }
                return false;
            }
        });

        gestureDetector.setFingerListener(new GestureDetector.FingerListener(){

            @Override
            public void onFingerCountChanged(int previousCount, int currentcount){
                //do something on finger count changes
            }
        });

        gestureDetector.setScrollListener(new GestureDetector.ScrollListener(){
            @Override
            public boolean onScroll(float displacement, float delta, float velocity){
                //do something on scroll
                return true;
            }
        });

        return gestureDetector;

    }

    @Override
    public void onAttachedToWindow() {
        Log.d("onAttachedToWindow","Successfully attached");
        super.onAttachedToWindow();
        // Open the options menu right away.
        // openOptionsMenu();
        setContentView(R.layout.live_card);
        mGestureDetector = createGestureDetector(this); // DECISIVE LINE
    }

If I uncomment the last line (decisive line) the activity fails with NoClassDefFoundError. Else, it doesn't and imports everything else successfully, including com.google.android.glass.touchpad.Gesture

MWiesner
  • 8,868
  • 11
  • 36
  • 70

1 Answers1

0

Even if the classes import at compile time, doesn't mean they will resolve at runtime.

Are you running this on actual Glass hardware with a recent software version? If you are running on something other than Glass itself, the classes that Gesture/GestureDetector bind to at runtime in the platform will not be present which would result in a NoClassDefFoundError.

The GDK merely provides a thin interface used at compile time and all the actual implementation is built in to the platform. This allows for platform/os changes to be made without requiring every developer to recompile/redeploy their APK.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Brandon Wuest
  • 206
  • 1
  • 2