android - Fatal Exception: String can't be cast to Spannable -
my app works exception of few devices. on 1 such device, fatal exception in 1 of activities. error java.lang.classcastexception: java.lang.string cannot cast android.text.spannable ... ... at android.widget.textview.setenabled(textview.java:1432)
stack trace
05-02 09:18:19.917: e/androidruntime(20587): fatal exception: main 05-02 09:18:19.917: e/androidruntime(20587): java.lang.classcastexception: java.lang.string cannot cast android.text.spannable 05-02 09:18:19.917: e/androidruntime(20587): @ android.widget.textview.setenabled(textview.java:1432) 05-02 09:18:19.917: e/androidruntime(20587): @ com.myapp.android.menu.loginfragment.checkifanyfieldisempty(loginfragment.java:512) 05-02 09:18:19.917: e/androidruntime(20587): @ com.myapp.android.menu.loginfragment.oncreateview(loginfragment.java:183) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.fragment.performcreateview(fragment.java:1460) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:911) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1088) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1444) 05-02 09:18:19.917: e/androidruntime(20587): @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:429) 05-02 09:18:19.917: e/androidruntime(20587): @ android.os.handler.handlecallback(handler.java:615) 05-02 09:18:19.917: e/androidruntime(20587): @ android.os.handler.dispatchmessage(handler.java:92) 05-02 09:18:19.917: e/androidruntime(20587): @ android.os.looper.loop(looper.java:137) 05-02 09:18:19.917: e/androidruntime(20587): @ android.app.activitythread.main(activitythread.java:4962) 05-02 09:18:19.917: e/androidruntime(20587): @ java.lang.reflect.method.invokenative(native method) 05-02 09:18:19.917: e/androidruntime(20587): @ java.lang.reflect.method.invoke(method.java:511) 05-02 09:18:19.917: e/androidruntime(20587): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1004) 05-02 09:18:19.917: e/androidruntime(20587): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:771) 05-02 09:18:19.917: e/androidruntime(20587): @ dalvik.system.nativestart.main(native method)
here snippets of code surrounding error.
xml layout code
<com.myapp.android.view.styledbutton android:id="@+id/login_sign_in" style="@style/button_blue" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/state_list_login" android:textcolor="@color/white" android:imeoptions="actiondone" android:padding="10dp" android:text="@string/sign_in" />
custom button java code
public class styledbutton extends button { //variables private final string bold = "fonts/arial.ttf"; private final string normal = "fonts/arial_bold.ttf"; private string mcustomfont = null; /** * constructor * @param context */ public styledbutton(context context) { super(context); } /** * constructor * @param context * @param attrs */ public styledbutton(context context, attributeset attrs) { super(context, attrs); setcustomattributes(attrs); } /** * set custom attributes * @param attrs */ private void setcustomattributes(attributeset attrs) { typedarray a=getcontext().obtainstyledattributes(attrs,r.styleable.styledtextview); mcustomfont = a.getstring(r.styleable.styledtextview_fontasset); if(mcustomfont != null) { if(!isineditmode()) { customfontmanager fontmanager = customfontmanager.getinstance(); super.settypeface(fontmanager.getfont(getcontext().getassets(), mcustomfont)); } } a.recycle(); } /** * set type face */ public void settypeface(typeface tf, int style) { customfontmanager fontmanager = customfontmanager.getinstance(); if(isineditmode()) { super.settypeface(tf,style); return; } if(mcustomfont!=null) { super.settypeface(fontmanager.getfont(getcontext().getassets(), mcustomfont)); return; } switch (style) { case typeface.normal: super.settypeface(fontmanager.getfont(getcontext().getassets(), normal)); break; case typeface.bold: super.settypeface(fontmanager.getfont(getcontext().getassets(), bold)); break; default: super.settypeface(fontmanager.getfont(getcontext().getassets(), normal)); break; } }
}
java code causing error
private styledbutton msignin; public void checkifanyfieldisempty() { if (memailempty || mpasswordempty) { msignin.setenabled(false); } else { msignin.setenabled(true); } }
the line of code msignin.setenabled(false) causing error. if comment out or replace both if , else read msignin.setenabled(true) app runs fine.
again. code works fine on majority of devices.
did make style button spannable? example, textview should
textview.settext("hai", textview.buffertype.spannable);
Comments
Post a Comment