5

I have a Java interface:

public interface NonHindiQuery {
    void onNonHindiQueryReceived(String Query);
}

I want to implement it on Kotlin class:

class MainActivity : AppCompatActivity() {...}

Q: How can I do it?

5
  • 3
    add , NonHindiQurary after AppCompatActivity() before class body Commented Jun 28, 2017 at 10:55
  • now i getting this error kotlin.NotImplementedError: An operation is not implemented: not implemented Commented Jun 28, 2017 at 11:00
  • you must implement interface methods in your class, you've get this error because MainActivity must implement void onNonHindiQuraryRecived(String Queary); or set your class as abstract. but you need first way Commented Jun 28, 2017 at 11:01
  • i implemented interface , then i get this error Commented Jun 28, 2017 at 11:12
  • this is how i did it class MainActivity : AppCompatActivity(),NonHindiQurary Commented Jun 28, 2017 at 11:13

1 Answer 1

28

It's simple:

class MainActivity : AppCompatActivity(), NonHindiQuery {
    override fun onNonHindiQueryReceived(q: String) {
        // <...>
    }
}

To get rid of kotlin.NotImplementedError remove TODO("not implemented") from the method body:

@kotlin.internal.InlineOnly
public inline fun TODO(reason: String): Nothing = 
    throw NotImplementedError("An operation is not implemented: $reason")
Sign up to request clarification or add additional context in comments.

2 Comments

@Alexander Romanov could you help me on this topic: stackoverflow.com/q/45293506/1830228
What rubbish. why they do such stupid things :) BTW this worked. thanks

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.