android - Listactivity error with jelly bean running device ( SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length) -
i have app start splash screen open listactivity rows, clicking on row opens activity containing textview, 2 buttons (one of opens infinite gallery, other opens custom dialog), , menu items (about, preference, exit).
this app runs on ginger bread when tested on galaxy s3 running jelly bean, opens when click on 1 of listactivity rows appears ignore click. log cat on eclipse shows :
span_exclusive_exclusive spans cannot have 0 length
however, there no force close (the listactivity scrolls , menu items work fine , ).
update:
noticed application: created eclipse since around 1 month ago name lets (trip
) , today testing (trip.apk
) on both ginger bread , jelly bean works perfectly.
but wanted change name trip
travel
, did not use refactor. instead created new project application name called travel
other things same previous app trip
including classes, res, , when tested jelly bean shows:
span_exclusive_exclusive spans cannot have 0 length
update 3 :
i solved problem :
i added line textviews in app :
android:textisselectable="true"
and line lead rows ignore click ,
so removed , both old , new app work fine both api .
update 4:
the above phrases related old issue , solved ,
the question :
my application work apis when tested with:
galaxy s3 running jelly bean work ,
but in eclipse log cat show error :
span_exclusive_exclusive spans cannot have 0 length
without affect application performance , idea solve error .
any explanation highly appreciated , thanks.
the code of project :
menu :
public class menu extends listactivity { string classes[] = { "introduction", "dreamstrip", "day one", "day two", "day three", "day four", "day five", "conclusion" }; @override protected void oncreate(bundle savedinstancestate) { this.requestwindowfeature(window.feature_no_title); super.oncreate(savedinstancestate); // create background whole list image listview lv = getlistview(); lv.setcachecolorhint(0); lv.setselector(android.r.color.transparent); lv.setpadding(30, 0, 30, 0); lv.setverticalscrollbarenabled(false); lv.setbackgroundresource(r.drawable.list_background); lv.setdivider(new colordrawable(0x00000000)); setlistadapter(new myarrayadapter(this, classes)); } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); string cheese = classes[position]; try { intent ourintent; if (position > 1 && position < 25) { class ourclass = class.forname("com.test.demo.myday"); ourintent = new intent(menu.this, ourclass); ourintent.putextra("cheese", cheese); } else { class ourclass = class.forname("com.test.demo." + cheese); ourintent = new intent(menu.this, ourclass); } startactivity(ourintent); } catch (classnotfoundexception e) { e.printstacktrace(); } } public boolean oncreateoptionsmenu(android.view.menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.cool_menu, menu); getlayoutinflater().setfactory(new factory() { public view oncreateview(string name, context context, attributeset attrs) { if (name.equalsignorecase( "com.android.internal.view.menu.iconmenuitemview")) { try { layoutinflater li = layoutinflater.from(context); final view view = li.createview(name, null, attrs); new handler().post(new runnable() { public void run() { view.setbackgroundresource(r.drawable.border3); ((textview) view).settextsize(25); ((textview) view).settypeface(fontfactory .getbfantezy(getbasecontext())); ((textview) view).settextcolor(color.red); } }); return view; } catch (inflateexception e) { } catch (classnotfoundexception e) { } } return null; } }); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.aboutus: intent = new intent("com.test.demo.about"); startactivity(i); break; case r.id.preferences: intent p = new intent("com.test.demo.prefs"); startactivity(p); break; case r.id.exit: finish(); break; } return false; } }
myarrayadapter:
public class myarrayadapter extends arrayadapter<string> { private final activity context; private final string[] classes; typeface tf; static class viewholder { public textview text; public imageview image; } public myarrayadapter(activity context, string[] classes) { super(context, r.layout.row, classes); this.context = context; this.classes = classes; tf = typeface.createfromasset(context.getassets(), "bfantezy.ttf"); } @override public view getview(int position, view convertview, viewgroup parent) { view rowview = convertview; if (rowview == null) { layoutinflater inflater = context.getlayoutinflater(); rowview = inflater.inflate(r.layout.row, null); viewholder viewholder = new viewholder(); viewholder.text = (textview) rowview.findviewbyid(r.id.row_label); viewholder.image = (imageview) rowview.findviewbyid(r.id.row_image); viewholder.text.settypeface(fontfactory.getbfantezy(getcontext())); rowview.settag(viewholder); } viewholder holder = (viewholder) rowview.gettag(); string s = classes[position]; holder.text.settext(s); if (s.equals("day one")) { holder.image.setimageresource(r.drawable.day1); } if (s.equals("day two")) { holder.image.setimageresource(r.drawable.day2); } if (s.equals("day three")) { holder.image.setimageresource(r.drawable.day3); } if (s.equals("day four")) { holder.image.setimageresource(r.drawable.day4); } if (s.equals("day five")) { holder.image.setimageresource(r.drawable.day5); } if (s.equals("conclusion")) { holder.image.setimageresource(r.drawable.day_concl); } if (s.equals("dreamstrip")) { holder.image.setimageresource(r.drawable.day_trip); } if (s.equals("introduction")) { holder.image.setimageresource(r.drawable.day_intr); } return rowview; } }
myday:
public class myday extends activity { final context context = this; private button button; textview tv2, tv3, tv4; string day; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on); boolean customtitlesupported = requestwindowfeature(window.feature_custom_title); setcontentview(r.layout.day); if (customtitlesupported) { getwindow().setfeatureint(window.feature_custom_title, r.layout.custom_title); } initializetextviews(); } private void initializetextviews() { tv2 = (textview) findviewbyid(r.id.day_tv1); tv2.settypeface(fontfactory.getbfantezy(getbasecontext())); tv3 = (textview) findviewbyid(r.id.day_tv3); tv3.settypeface(fontfactory.getdroidnaskh(getbasecontext())); day = getintent().getstringextra("cheese"); if (day.equalsignorecase("day one")) { tv2.settext(html.fromhtml(getstring(r.string.beginning))); tv3.settext(html.fromhtml(getstring(r.string.day1))); button = (button) findviewbyid(r.id.city_button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // custom dialog final dialog dialog = new dialog(context, r.style.cust_dialog); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.custom_dialog); // set custom dialog components - text, image , button textview text = (textview) dialog .findviewbyid(r.id.dialog_text); text.settypeface(fontfactory.getbfantezy(getbasecontext())); text.settext(html .fromhtml(getstring(r.string.torusim_places_1))); button dialogbutton = (button) dialog .findviewbyid(r.id.dialog_button); dialogbutton.settypeface(fontfactory .getbfantezy(getbasecontext())); // if button clicked, close custom dialog dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { dialog.dismiss(); } }); dialog.show(); } }); } else if (day.equalsignorecase("day two")) { tv2.settext(html.fromhtml(getstring(r.string.beginning))); tv3.settext(html.fromhtml(getstring(r.string.day2))); button = (button) findviewbyid(r.id.city_button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // custom dialog final dialog dialog = new dialog(context, r.style.cust_dialog); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.custom_dialog); // set custom dialog components - text, image , button textview text = (textview) dialog .findviewbyid(r.id.dialog_text); text.settypeface(fontfactory.getbfantezy(getbasecontext())); text.settext(html .fromhtml(getstring(r.string.torusim_places_2))); button dialogbutton = (button) dialog .findviewbyid(r.id.dialog_button); dialogbutton.settypeface(fontfactory .getbfantezy(getbasecontext())); // if button clicked, close custom dialog dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { dialog.dismiss(); } }); dialog.show(); } }); } else if (day.equalsignorecase("day three")) { tv2.settext(html.fromhtml(getstring(r.string.beginning))); tv3.settext(html.fromhtml(getstring(r.string.day3))); button = (button) findviewbyid(r.id.city_button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // custom dialog final dialog dialog = new dialog(context, r.style.cust_dialog); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.custom_dialog); // set custom dialog components - text, image , button textview text = (textview) dialog .findviewbyid(r.id.dialog_text); text.settypeface(fontfactory.getbfantezy(getbasecontext())); text.settext(html .fromhtml(getstring(r.string.torusim_places_3))); button dialogbutton = (button) dialog .findviewbyid(r.id.dialog_button); dialogbutton.settypeface(fontfactory .getbfantezy(getbasecontext())); // if button clicked, close custom dialog dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { dialog.dismiss(); } }); dialog.show(); } }); } else if (day.equalsignorecase("day four")) { tv2.settext(html.fromhtml(getstring(r.string.beginning))); tv3.settext(html.fromhtml(getstring(r.string.day4))); button = (button) findviewbyid(r.id.city_button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // custom dialog final dialog dialog = new dialog(context, r.style.cust_dialog); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.custom_dialog); // set custom dialog components - text, image , button textview text = (textview) dialog .findviewbyid(r.id.dialog_text); text.settypeface(fontfactory.getbfantezy(getbasecontext())); text.settext(html .fromhtml(getstring(r.string.torusim_places_4))); button dialogbutton = (button) dialog .findviewbyid(r.id.dialog_button); dialogbutton.settypeface(fontfactory .getbfantezy(getbasecontext())); // if button clicked, close custom dialog dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { dialog.dismiss(); } }); dialog.show(); } }); } else if (day.equalsignorecase("day five")) { tv2.settext(html.fromhtml(getstring(r.string.beginning))); tv3.settext(html.fromhtml(getstring(r.string.day5))); button = (button) findviewbyid(r.id.city_button); button.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // custom dialog final dialog dialog = new dialog(context, r.style.cust_dialog); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.custom_dialog); // set // custom dialog components - text, image , button textview text = (textview) dialog .findviewbyid(r.id.dialog_text); text.settypeface(fontfactory.getbfantezy(getbasecontext())); text.settext(html .fromhtml(getstring(r.string.torusim_places_5))); button dialogbutton = (button) dialog .findviewbyid(r.id.dialog_button); dialogbutton.settypeface(fontfactory .getbfantezy(getbasecontext())); // if button clicked, close custom dialog dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { dialog.dismiss(); } }); dialog.show(); } }); } } public void handleclick(view v) { // create intent start new activity. intent intent = new intent(); intent.setclass(this, daygallery.class); intent.putextra("dayname", day); startactivity(intent); } }
logcat:
d/abslistview(14159): motionrecognitionmanager d/dalvikvm(14159): gc_for_alloc freed 81k, 9% free 12164k/13315k, paused 13ms, total 13ms i/dalvikvm-heap(14159): grow heap (frag case) 14.306mb 1555216-byte allocation d/dalvikvm(14159): gc_concurrent freed 2k, 8% free 13681k/14855k, paused 12ms+1ms, total 20ms d/dalvikvm(14159): gc_for_alloc freed 0k, 8% free 13681k/14855k, paused 10ms, total 10ms i/dalvikvm-heap(14159): grow heap (frag case) 16.941mb 2764816-byte allocation d/dalvikvm(14159): gc_concurrent freed 0k, 7% free 16381k/17607k, paused 12ms+2ms, total 23ms d/libegl(14159): loaded /system/lib/egl/libegl_mali.so d/libegl(14159): loaded /system/lib/egl/libglesv1_cm_mali.so d/libegl(14159): loaded /system/lib/egl/libglesv2_mali.so d/(14159): device driver api match d/(14159): device driver api version: 10 d/(14159): user space api version: 10 d/(14159): mali: revision=linux-r2p4-02rel0 build_date=tue oct 16 15:37:13 kst 2012 d/openglrenderer(14159): enabling debug mode 0 d/dalvikvm(14159): gc_for_alloc freed 1732k, 16% free 15672k/18439k, paused 19ms, total 19ms e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length d/dalvikvm(14159): gc_concurrent freed 691k, 13% free 16102k/18439k, paused 13ms+2ms, total 27ms e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length w/openglrenderer(14159): shape round rect large rendered texture (680x12472, max=4096x4096) w/openglrenderer(14159): shape round rect large rendered texture (688x12480, max=4096x4096) e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length e/spannablestringbuilder(14159): span_exclusive_exclusive spans cannot have 0 length
to understand happening here, starts design decision textview
should , shouldn't be. according the android source textview:
/** * displays text user , optionally allows them edit it. textview * complete text editor, basic class configured not * allow editing; see {@link edittext} subclass configures text * view editing.
this means that, if you're doing putting piece of text on screen, hidden behind full text highlight, selection , editing facilities. has happened here little tweak resolve issue in them appears have interfered other functionality, , created log lines. case given more weight by, say, nexus 7 error "span_exclusive_exclusive spans cannot have 0 length", in seem on android versions situation can resolved disabling autocomplete in text (entry) fields:
view.setinputtype( inputtype.type_class_text | inputtype.type_text_flag_no_suggestions );
this done in xml using corresponding tags textview
:
android:inputtype="none"
the lines in question appear have arrived in android 4.1 (jelly bean), in setspan
function of spannablestringbuilder
(eg. 2.2.3 source vs 4.1.1 source). log line triggered attempt set span within string of 0 length. why setting no (sub) section of text needs selected should avoid error, either above tip or using:
android:textisselectable="false" android:editable="false"
a more speculative solution maybe ensure there never blank string in textview
adding character "\u200b" (a non-shown blank character of 0 width) every string put in textview
s, either overriding settext
(to add end of string) in custom textview
or putting in code every string sent textview
s.
for delving android system , overriding parts of it, according this piece of android source looks mght possible solve issue following. however, there absolutely no guarantee works. brave (foolhardy) can write complete spannablestringbuilder ....
creating own form of
spannablestringbuilder
traps condition. example stops quietly, rather stopping loudly, per original:import android.text.spannablestringbuilder; public class myspannablestringbuilder extends spannablestringbuilder { // taken spannablestringbuilder.java private static final int mark = 1; private static final int point = 2; private static final int start_mask = 0xf0; private static final int end_mask = 0x0f; private static final int start_shift = 4; myspannablestringbuilder() { super(); } myspannablestringbuilder(charsequence text) { super(text); } myspannablestringbuilder(charsequence text, int start, int end) { super(text, start, end); } @override public void setspan(object what, int start, int end, int flags) { // determine if error going triggered, if fail silently int flagsstart = (flags & start_mask) >> start_shift; int flagsend = flags & end_mask; if (flagsstart == point && flagsend == mark && start == end) { return; } // good, call real routine super.setspan(what, flagsstart, end, flagsend); } }
creating
myeditablefactory extends editable.factory
, setting return spannablestringbuilder:import android.text.editable; public class myeditablefactory extends editable.factory { private static myeditablefactory sinstance = new myeditablefactory(); /** * returns editable factory. */ public static editable.factory getinstance() { return sinstance; } public editable neweditable(charsequence source) { return new myspannablestringbuilder(source); } }
other writing custom version of os , putting on phone, i'm not sure else possible.
all suggestions improvement welcome, feedback on using code in various os situations.
Comments
Post a Comment