Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
pdiaz
16,073 PointsCan someone help me with the Gesture Detector?
Hello, my code doesn't have any errors except for my last Gesture Detector.
public class Flipper extends Activity {
ViewFlipper page;
Animation animFlipInForward;
Animation animFlipOutForward;
Animation animFlipInBackward;
Animation animFlipOutBackward;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flipper);
page = (ViewFlipper)findViewById(R.id.viewFlipper);
animFlipInForward = AnimationUtils.loadAnimation(this, R.anim.flipin);
animFlipOutForward = AnimationUtils.loadAnimation(this, R.anim.flipout);
animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.flipin_reverse);
animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.flipout_reverse);
}
private void SwipeRight(){
page.setInAnimation(animFlipInBackward);
page.setOutAnimation(animFlipOutBackward);
page.showPrevious();
}
private void SwipeLeft(){
page.setInAnimation(animFlipInForward);
page.setOutAnimation(animFlipOutForward);
page.showNext();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(event);
}
GestureDetector.SimpleOnGestureListener simpleOnGestureListener
= new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float sensitvity = 50;
if((e1.getX() - e2.getX()) > sensitvity){
SwipeLeft();
}else if((e2.getX() - e1.getX()) > sensitvity){
SwipeRight();
}
return true;
}
};
GestureDetector gestureDetector = new GestureDetector(simpleOnGestureListener);
}
pdiaz
16,073 PointsThe very last gesture detector: GestureDetector gestureDetector = new GestureDetector(simpleOnGestureListener);
In android studio, it shows the GestureDetector in: = new GestureDetector(simpleOnGestureListener); to have a line through it.
Gunjeet Hattar
14,483 PointsIf it has a line through it. It means the method is deprecated i.e. no longer in use and some new method has replaced it.
But does logcat show any error, or its just the line across the method?
pdiaz
16,073 PointsYes, this is what the logcat said.
6:25:05 PM IOException: The filename, directory name, or volume label syntax is incorrect: The filename, directory name, or volume label syntax is incorrect 6:25:11 PM NullPointerException: null
Gunjeet Hattar
14,483 PointsThe new GestureDetector method takes (Content context, GestureDetector.OnGestureListener listener)
Somehow your listener is returning a null.
Also the file name, directory error is related to a incorrect path to a file. I didn't really spot any reference to a file resource, so assuming its related to something else
pdiaz
16,073 Pointsany suggestions of fixing it?
Gunjeet Hattar
14,483 PointsGunjeet Hattar
14,483 Pointswhat exactly are those error? Can you paste them here.