0

I have next java class:

public interface Callbacks {
     void onImagePickerError(Exception e, Library.ImageSource source, int type);

    void onImagePicked(File imageFile, Library.ImageSource source, int type);

    void onCanceled(Library.ImageSource source, int type);
}

and next abstract class extended interface:

public abstract class DefaultCallback implements Callbacks {

    @Override
    public void onImagePickerError(Exception e, Library.ImageSource source, int type) {
    }

    @Override
    public void onCanceled(Library.ImageSource source, int type) {
    }
}

In my case need in one place extend this interface and use it when callback coming from outher library.

In my android kotlin code looks like this:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        Library.handleActivityResult(requestCode, resultCode, data, this, callback)
    }

private val callback = object: Library.Callbacks {
    override fun onImagePicked(imageFile: File?, source: Library.ImageSource?, type: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onImagePickerError(e: Exception?, source: Library.ImageSource?, type: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onCanceled(source: Library.ImageSource?, type: Int) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}

It's nothing special. But in compile time i have error:

Error:(239, 28) Object is not abstract and does not implement abstract member public abstract fun onImagesPicked(@NonNull p0: (Mutable)List<File!>, p1: Library.ImageSource!, p2: Int): Unit defined in github.library.path.Library.Callbacks
Error:(240, 9) 'onImagePicked' overrides nothing

1) why error have incorrect method name - onImagesPicked

2) why this not compile?

I try this and it's worked!

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        Library.handleActivityResult(requestCode, resultCode, data, this, object: DefaultCallback() {
            fun onImagePicked(imageFile: File?, source: Library.ImageSource?, type: Int) {
                log("emm") //not worked and method useless
            }

            override fun onImagesPicked(p0: List<File>, p1: Library.ImageSource, p2: Int) {
                photoFileUri = Uri.fromFile(p0[0])
                setUpPhoto()
                log("worked") //worked! how?
            }
        })
    }
4
  • does not implement abstract member public abstract fun onImagesPicked(@NonNull p0: (Mutable)List<File!>, ...) - It seems the method should accept List argument, but you declared a File parameter: imageFile: File?. Commented Feb 1, 2018 at 22:58
  • first two methods - i'ts library code Commented Feb 1, 2018 at 23:10
  • What I'm saying is the method you declared doesn't match the method that's required. You need override fun onImagesPicked(p0: List<File>, ...), not override fun onImagesPicked(imageFile: File?, ...). That's why the method which logs "worked" works: it shares the same method signature as the method that is required, while your onImagesPicked(imageFile: File?, ...) does not match. You cannot simply change the parameter types & expect overriding to work. Commented Feb 1, 2018 at 23:16
  • 1
    It looks like the Callbacks interface that Kotlin is seeing is not the same Callbacks interface you're seeing in your editor. Do you need to rebuild something? Maybe your pom/gradle.build is out of date? Some dependency somewhere may need to be fixed. Commented Feb 2, 2018 at 0:29

1 Answer 1

1

It's pretty obvious: your private val callback doesn't have method onImagesPicked(p0: List<File>).

But there may be several causes of this error:

  1. Kotlin sees some another Callbacks interface then public interface Callbacks which we see. It can be baecause of
    1. Typo in import
    2. Wrong import
    3. Another version of library
  2. The code you've posted above is not completely up-to-date
Sign up to request clarification or add additional context in comments.

1 Comment

you right - Another version of library. Invalidate Cache -> Restart -> Clean -> Rebuild help .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.