-1

I'm creating an EditText subclass and I want to make an Editable variable to pass to the super class.

When I originally tried

private Editable unicodeText = new Editable();

I got the error

'Editable' is abstract; cannot be instantiated

Searching for this error in Google did not return any helpful results, so now that I have found the answer I am adding this question with an answer below.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • 2
    This wasn't a helpful result? http://stackoverflow.com/questions/8519943/class-room-is-abstract-cannot-be-instantiated – OneCricketeer Sep 19 '16 at 03:41
  • @cricket_007, My question was more about how to make an `Editable` object and not just the "can't instantiate something abstract" problem. [Android How can I Convert a String to a Editable](http://stackoverflow.com/questions/13352531/android-how-can-i-convert-a-string-to-a-editable) was an appropriately marked duplicate. – Suragch Sep 19 '16 at 03:54
  • Your question didn't include your ultimate goal -- it just listed an error about you trying to instantiate abstract class, an error for which there are plenty of answers already. It's not feasable or helpful to have a separate question for instantiating every subclass of an abstract class out there. If your question was "what's a good subclass for wrapping a String into an Editable," you should have asked that... though it'd probably be off topic as a request for an external resource. – yshavit Sep 19 '16 at 04:03

1 Answers1

1

Editable is an interface, not a class, and as such cannot be instantiated.

Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces. (docs)

However, the class SpannableStringBuilder implements Editable so you can do the following:

private Editable unicodeText = new SpannableStringBuilder();

Thanks to this answer for setting me on the right track.

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393