0

I need to create a custom class by extending SpannableStringBuilder.

I havent even added anything to the class yet. So my class goes like this.

public class xyz extends SpannableStringBuilder{

}

But when I try to use this class instead of SpannableStringBuilder app crashes. It is working fine when I use SpannableStringBuilder.

I have tried adding the constructors too.

SadeepDarshana
  • 1,057
  • 18
  • 34
  • Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Oct 09 '15 at 13:25

1 Answers1

1

When you call xyz(), are you passing in any parameters? If so, make sure you call the appropriate super() constructor from your xyz constructor.

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
  • Im not calling a constructor, im just casting. `myvariable =(xyz)(textView.getText());` not working myvariable =(SpannableStringBuilder)(textView.getText()); working. – SadeepDarshana Oct 09 '15 at 14:21
  • `xyz spannable =(xyz)(textView.getText());` – SadeepDarshana Oct 09 '15 at 14:24
  • When I replace xyz with SpannableStringBuilder in the above line it works fine @Justin – SadeepDarshana Oct 09 '15 at 14:26
  • Have you tried `xyz spannable = new xyz(textView.getText());`? – JstnPwll Oct 09 '15 at 14:28
  • Yes it doesnt work. I mean the `textView` here is a EdidText. So it brings errors when editing the text later. (wrks for this statement only) – SadeepDarshana Oct 09 '15 at 14:30
  • What does your error say when the cast doesn't work? – JstnPwll Oct 09 '15 at 14:32
  • Caused by: java.lang.ClassCastException: android.text.SpannableStringBuilder cannot be cast to com.esfsd.fsdfsd.qwerty.MainActivity$xyz – SadeepDarshana Oct 09 '15 at 14:35
  • I think it's failing because xyz is an inner class of MainActivity. I would separate it out into its own java file and make it its own class. – JstnPwll Oct 09 '15 at 14:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91864/discussion-between-sadeepdarshana-and-justin-powell). – SadeepDarshana Oct 09 '15 at 14:48
  • not working yet, thanks for ur time. btw i'm doing this all to extent SpannableStringBuilder so that i can make a Serializable SpannableStringBuilder and store data in a file. Converting between html is not sufficiant for me. (Im creating a rich text editor and want to save the doc). Any alternatives for this? @Justin – SadeepDarshana Oct 09 '15 at 14:53