-3

When i Run my code in android studio, the following error message is displayed

no suitable constructor found for GestureDetectorCompat

What does this mean and how do i solve this issue?

This is part of the code,see below  

com.example.curtis.swiperdiaper;

 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.widget.TextView;
 import android.view.MotionEvent;
 import android.view.GestureDetector;
 import android.support.v4.view.GestureDetectorCompat;

private TextView ccMessage;
 //the below is causing an error //
"private GestureDetectorCompat gestureDetector;"
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ccMessage = (TextView)findViewById(R.id.ccMessage);
    this.gestureDetector = new GestureDetectorCompat();
}
CAC
  • 45
  • 1
  • 3
  • 11

1 Answers1

0

What that message means is you are calling the method without parameters and there are no constructor that match that condition (signature)

According to this documentation

http://developer.android.com/reference/android/support/v4/view/GestureDetectorCompat.html

There are 2 constructors one that take 2 parameters and one which takes 3

One way to solve this is to add implements OnGestureListener to your view or activity. for example

Class MyActivity extendes Activity implements OnGestureListener

And from your view or activity create the gestureDetector like this

this.gestureDetector = new GestureDetectorCompat(this,this);

The first parameter is a Context and the second is a class that implements OnGestureListener in these they are the same class and that is the reason we pass this as both parameters

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99