0

I want to extend Chronometer class and add my code.

How I could do it? I tried, but I can't get Chronometer constructor with View field. I get an exception, it is obvious:

...
android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.mantas.test.ChronometerV2
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
...

My code:

public class ChronometerV2 extends Chronometer{
    public ChronometerV2(Contex context){
        super(contex);
    }
}

and initiation:

ChronometerV2 c2 = findViewById(R.id.chronometerv2);

I am passing View here, but Chronometer only has constructor with Context field. How to do it?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Mantaz
  • 333
  • 1
  • 4
  • 12
  • You did not override the two-parameter constructor. See [this](https://stackoverflow.com/q/9195713/115145) for more. – CommonsWare Oct 20 '19 at 19:16

1 Answers1

1

Add this constructor:

public ChronometerV2(Context context, AttributeSet attrs) {
    super(context, attrs);
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216