Listactivity误差果冻豆运行设备(SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有长度为零) [英] Listactivity error with jelly bean running device ( SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length)

查看:640
本文介绍了Listactivity误差果冻豆运行设备(SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有长度为零)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序开始启动画面,然后打开listactivity行,点击任何行都将打开包含一个TextView,两个按钮的活动(其中一个打开了一个无限画廊,对方打开自定义对话框),和菜单项(约,preference,退出)。

该应用程序运行在完美的姜饼,但是当一个星系S3运行果冻豆测试时,它通常会打开,但是当你点击的listactivity行之一似乎忽略的点击。关于日食的记录猫显示:

  SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个长度为零
 

然而,没有强制关闭(通常是listactivity卷轴和菜单项做工精细)。

更新:
我发现了一些这个应用程序:我创造了它与Eclipse,因为各地在一个月前与一个名字可以说(之旅)今天测试( trip.apk 两个姜饼和果冻豆它完美的作品)。

不过,我想从更改名称之旅旅游,我没有使用重构。相反,我创建了名为应用程序名称的新项目旅游,但所有其他的事情都是一样的previous应用之旅包括类,资源,当与果冻豆显示测试:

  SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个长度为零
 

更新3:

我解决了这个问题:

我添加了此行我的应用程序的所有TextViews是:

 安卓textIsSelectable =真
 

和该行导致行忽视了一下,

所以我删除了它,现在老的和新的应用程序正常工作与这两个API。

更新4:

与老问题,已经解决了上述短语,

现在的问题是:

我的应用程序与所有API完美的工作,但与测试:

银河S3运行果冻豆的工作也很好,

但是在日食记录猫展错误:

  SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个长度为零
 

不影响应用程序性能,任何想法来解决这个错误。

任何解释,将是非常美联社preciated,谢谢。

我的项目的code:

菜单:

 公共类菜单扩展ListActivity {

    字符串类[] = {导言,DreamsTrip,第一天,第二天,
            第三天,第四天,五节,结论};

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        //创建背景整个名单形象
        ListView的LV = getListView();
        lv.setCacheColorHint(0);
        lv.setSelector(android.R.color.transparent);
        lv.setPadding(30,0,30,0);
        lv.setVerticalScrollBarEnabled(假);
        lv.setBackgroundResource(R.drawable.list_background);
        lv.setDivider(新ColorDrawable(00000000));
        setListAdapter(新MyArrayAdapter(本,班));
    }

    @覆盖
    保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
        super.onListItemClick(L,V,位置ID);
        奶酪条=类[位置]
        尝试 {
            意图ourIntent;
            如果(仓位大于1&安培;&安培;位置α25){
                类ourClass =的Class.forName(com.test.demo.MyDay);
                ourIntent =新的意图(菜单。该,ourClass);
                ourIntent.putExtra(奶酪,干酪);
            } 其他 {
                类ourClass =的Class.forName(com.test.demo。+奶酪);
                ourIntent =新的意图(菜单。该,ourClass);
            }
            startActivity(ourIntent);
        }赶上(ClassNotFoundException异常E){
            e.printStackTrace();
        }
    }

    公共布尔onCreateOptionsMenu(android.view.Menu菜单){
        MenuInflater充气= getMenuInflater();
        inflater.inflate(R.menu.cool_menu,菜单);
        getLayoutInflater()。setFactory(新厂(){

            公共查看onCreateView(字符串名称,上下文的背景下,
                    AttributeSet中的ATTRS){
                如果(name.equalsIgnoreCase(
                        com.android.internal.view.menu.IconMenuItemView)){
                    尝试 {
                        LayoutInflater李= LayoutInflater.from(上下文);
                        最终的视图中查看= li.createView(姓名,空,ATTRS);
                        新的处理程序()。后(新的Runnable(){

                            公共无效的run(){
                                view.setBackgroundResource(R.drawable.border3);
                                ((TextView中)查看).setTextSize(25);
                                ((TextView中)查看).setTypeface(FontFactory
                                        .getBFantezy(getBaseContext()));
                                ((TextView中)查看).setTextColor(Color.RED);
                            }
                        });
                        返回查看;
                    }赶上(InflateException E){
                    }赶上(ClassNotFoundException异常E){
                    }
                }
                返回null;
            }
        });
        返回super.onCreateOptionsMenu(菜单);
    }

    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        开关(item.getItemId()){
        案例R.id.aboutUs:
            意图I =新的意向书(com.test.demo.ABOUT);
            startActivity(ⅰ);
            打破;
        案例R.id. preferences:
            意图P =新的意向书(com.test.demo preFS。);
            startActivity(对);
            打破;
        案例R.id.exit:
            完();
            打破;
        }
        返回false;
    }
}
 

MyArrayAdapter:

 公共类MyArrayAdapter扩展ArrayAdapter<字符串> {

    私人最终活动范围内;
    私人最终的String []班;
    字样TF;

    静态类ViewHolder {

        公共TextView的文字;
        公众ImageView的形象;
    }

    公共MyArrayAdapter(活动的背景下,的String []班){
        超(背景下,R.layout.row,班);
        this.context =背景;
        this.classes =班;
        TF = Typeface.createFromAsset(context.getAssets(),BFantezy.ttf);
    }

    @覆盖
    公共查看getView(INT位置,查看convertView,ViewGroup中父){
        查看rowView = convertView;
        如果(rowView == NULL){
            LayoutInflater充气= context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.row,NULL);
            ViewHolder viewHolder =新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支架=(ViewHolder)rowView.getTag();
        字符串s =类[位置]
        holder.text.setText(多个);
        如果(s.equals()一节){
            holder.image.setImageResource(R.drawable.day1);
        }
        如果(s.equals(第二日)){
            holder.image.setImageResource(R.drawable.day2);
        }
        如果(s.equals(第三天)){
            holder.image.setImageResource(R.drawable.day3);
        }
        如果(s.equals(第四天)){
            holder.image.setImageResource(R.drawable.day4);
        }
        如果(s.equals(第五天)){
            holder.image.setImageResource(R.drawable.day5);
        }
        如果(s.equals(结论)){
            holder.image.setImageResource(R.drawable.day_concl);
        }
        如果(s.equals(DreamsTrip)){
            holder.image.setImageResource(R.drawable.day_trip);
        }
        如果(s.equals(导言)){
            holder.image.setImageResource(R.drawable.day_intr);
        }
        返回rowView;
    }
}
 

MyDay:

 公共类MyDay延伸活动{

    最终的上下文语境=这一点;
    私人Button按钮;
    TextView的TV2,TV3,TV4;
    字符串日;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        。getWindow()addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        布尔customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        的setContentView(R.layout.day);
        如果(customTitleSupported){
            getWindow()。setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.custom_title);
        }
        initializeTextViews();
    }

    私人无效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()));
        天= getIntent()getStringExtra(奶酪)。
        如果(day.equalsIgnoreCase(第一天)){
            tv2.setText(Html.fromHtml(的getString(R.string.beginning)));
            tv3.setText(Html.fromHtml(的getString(R.string.day1)));
            按钮=(按钮)findViewById(R.id.city_button);
            button.setOnClickListener(新OnClickListener(){

                公共无效的onClick(查看为arg0){
                    //自定义对话框
                    最后一个对话框对话框=新的对话框(背景下,
                            R.style.cust_dialog);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog);
                    //设置自定义对话框组件 - 文字,图片和按钮
                    TextView的文字=(TextView的)对话
                            .findViewById(R.id.dialog_text);
                    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
                    text.setText(HTML
                            .fromHtml(的getString(R.string.torusim_places_1)));
                    按钮dialogBu​​tton =(按钮)对话框
                            .findViewById(R.id.dialog_Button);
                    dialogBu​​tton.setTypeface(FontFactory
                            .getBFantezy(getBaseContext()));
                    //如果单击按钮,关闭定制对话框
                    dialogBu​​tton.setOnClickListener(新OnClickListener(){

                        公共无效的onClick(视图v){
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }否则,如果(day.equalsIgnoreCase(第二日)){
            tv2.setText(Html.fromHtml(的getString(R.string.beginning)));
            tv3.setText(Html.fromHtml(的getString(R.string.day2)));
            按钮=(按钮)findViewById(R.id.city_button);
            button.setOnClickListener(新OnClickListener(){

                公共无效的onClick(查看为arg0){
                    //自定义对话框
                    最后一个对话框对话框=新的对话框(背景下,
                            R.style.cust_dialog);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog);
                    //设置自定义对话框组件 - 文字,图片和按钮
                    TextView的文字=(TextView的)对话
                            .findViewById(R.id.dialog_text);
                    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
                    text.setText(HTML
                            .fromHtml(的getString(R.string.torusim_places_2)));
                    按钮dialogBu​​tton =(按钮)对话框
                            .findViewById(R.id.dialog_Button);
                    dialogBu​​tton.setTypeface(FontFactory
                            .getBFantezy(getBaseContext()));
                    //如果单击按钮,关闭定制对话框
                    dialogBu​​tton.setOnClickListener(新OnClickListener(){

                        公共无效的onClick(视图v){
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }否则,如果(day.equalsIgnoreCase(第三天)){
            tv2.setText(Html.fromHtml(的getString(R.string.beginning)));
            tv3.setText(Html.fromHtml(的getString(R.string.day3)));
            按钮=(按钮)findViewById(R.id.city_button);
            button.setOnClickListener(新OnClickListener(){

                公共无效的onClick(查看为arg0){
                    //自定义对话框
                    最后一个对话框对话框=新的对话框(背景下,
                            R.style.cust_dialog);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog);
                    //设置自定义对话框组件 - 文字,图片和按钮
                    TextView的文字=(TextView的)对话
                            .findViewById(R.id.dialog_text);
                    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
                    text.setText(HTML
                            .fromHtml(的getString(R.string.torusim_places_3)));
                    按钮dialogBu​​tton =(按钮)对话框
                            .findViewById(R.id.dialog_Button);
                    dialogBu​​tton.setTypeface(FontFactory
                            .getBFantezy(getBaseContext()));
                    //如果单击按钮,关闭定制对话框
                    dialogBu​​tton.setOnClickListener(新OnClickListener(){

                        公共无效的onClick(视图v){
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }否则,如果(day.equalsIgnoreCase(第四天)){
            tv2.setText(Html.fromHtml(的getString(R.string.beginning)));
            tv3.setText(Html.fromHtml(的getString(R.string.day4)));
            按钮=(按钮)findViewById(R.id.city_button);
            button.setOnClickListener(新OnClickListener(){

                公共无效的onClick(查看为arg0){
                    //自定义对话框
                    最后一个对话框对话框=新的对话框(背景下,
                            R.style.cust_dialog);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog);
                    //设置自定义对话框组件 - 文字,图片和按钮
                    TextView的文字=(TextView的)对话
                            .findViewById(R.id.dialog_text);
                    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
                    text.setText(HTML
                            .fromHtml(的getString(R.string.torusim_places_4)));
                    按钮dialogBu​​tton =(按钮)对话框
                            .findViewById(R.id.dialog_Button);
                    dialogBu​​tton.setTypeface(FontFactory
                            .getBFantezy(getBaseContext()));
                    //如果单击按钮,关闭定制对话框
                    dialogBu​​tton.setOnClickListener(新OnClickListener(){

                        公共无效的onClick(视图v){
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }否则,如果(day.equalsIgnoreCase(第五天)){
            tv2.setText(Html.fromHtml(的getString(R.string.beginning)));
            tv3.setText(Html.fromHtml(的getString(R.string.day5)));
            按钮=(按钮)findViewById(R.id.city_button);
            button.setOnClickListener(新OnClickListener(){

                公共无效的onClick(查看为arg0){
                    //自定义对话框
                    最后一个对话框对话框=新的对话框(背景下,
                            R.style.cust_dialog);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog); // 摆好
                    //自定义对话框组件 - 文字,图片和按钮
                    TextView的文字=(TextView的)对话
                            .findViewById(R.id.dialog_text);
                    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));
                    text.setText(HTML
                            .fromHtml(的getString(R.string.torusim_places_5)));
                    按钮dialogBu​​tton =(按钮)对话框
                            .findViewById(R.id.dialog_Button);
                    dialogBu​​tton.setTypeface(FontFactory
                            .getBFantezy(getBaseContext()));
                    //如果单击按钮,关闭定制对话框
                    dialogBu​​tton.setOnClickListener(新OnClickListener(){

                        公共无效的onClick(视图v){
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }
    }

    公共无效handleClick(视图v){
        //创建一个意图,开始新的活动。
        意向意图=新的意图();
        intent.setClass(这一点,Da​​yGallery.class);
        intent.putExtra(DAYNAME,日);
        startActivity(意向);
    }
}
 

logcat的:

  D / AbsListView(14159):获取MotionRecognitionManager
D / dalvikvm(14159):GC_FOR_ALLOC释放81K,9%的自由12164K / 13315K,暂停13毫秒,总
13毫秒
I / dalvikvm堆(14159):成长堆(破片的情况下),以14.306MB为1555216字节分配
D / dalvikvm(14159):GC_CONCURRENT释放2K,8%免费13681K / 14855K,暂停12毫秒+ 1毫秒,
共有20毫秒
D / dalvikvm(14159):GC_FOR_ALLOC释放0K,免费13681K / 14855K,暂停10毫秒,共8%
10毫秒
I / dalvikvm堆(14159):成长堆(破片的情况下),以16.941MB为2764816字节分配
D / dalvikvm(14159):GC_CONCURRENT释放0K,7%免费16381K / 17607K,暂停12毫秒+ 2ms的,
总23MS
D / libEGL(14159):加载/system/lib/egl/libEGL_mali.so
D / libEGL(14159):加载/system/lib/egl/libGLESv1_CM_mali.so
D / libEGL(14159):加载/system/lib/egl/libGLESv2_mali.so
D /(14159):设备驱动程序API匹配
D /(14159):设备驱动程序API版本:10
D /(14159):用户空间API版本:10
D /(14159):马里:版本= Linux的r2p4-02rel0 BUILD_DATE =周二10月16日15时37分13秒KST 2012
D / OpenGLRenderer(14159):启用调试模式0
D / dalvikvm(14159):GC_FOR_ALLOC释放1732K,16%免费15672K / 18439K,暂停19ms,
总19ms
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
D / dalvikvm(14159):GC_CONCURRENT释放691K,13%免费16102K / 18439K,暂停13毫秒+ 2ms的,
总27ms
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
W / OpenGLRenderer(14159):形状圆矩形太大,被渲染到纹理
(680x12472,上限= 4096×4096)
W / OpenGLRenderer(14159):形状圆矩形太大,被渲染到纹理
(688x12480,上限= 4096×4096)
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
E / SpannableStringBuilder(14159):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零
长度
 

解决方案

要了解这里发生的一切,这一切与一个关于什么是的TextView 应该和设计决定启动不应该。据<一href="http://$c$c.metager.de/source/xref/android/4.1.1/frameworks/base/core/java/android/widget/TextView.java"相对=nofollow> Android的源代码的TextView :

  / **
 *显示的文本给用户,可选择允许他们进行编辑。一个TextView
 *是一个完整的文本编辑器,但是其基本类配置为不
 *允许编辑;见{@link的EditText}的一个子类,配置文本
 *视图进行编辑。
 

这意味着,即使你正在做的是把一段文字的屏幕,背后隐藏的是全文的亮点,选择和编辑设施。本案的情况是,一个小调整来解决这样一个问题:他们似乎已经干扰了其他一些功能,并创造了一些日志行。这是由,比方说,<一个给定的更重的情况下, href="http://stackoverflow.com/questions/13488695/nexus-7-error-span-exclusive-exclusive-spans-cannot-have-a-zero-length?rq=1">Nexus 7错误&QUOT; SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零长度QUOT; ,其中它似乎在某些版本的Andr​​oid这种情况下,可以通过禁用自动完成文本来解决(项)字段:

  View.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
 

在XML使用相应的标签这也可以做一个的TextView

 安卓inputType =无
 

在讨论的线条似乎已经到达的Andr​​oid 4.1(果冻豆),在 SpannableStringBuilder setSpan 功能>(例如,<一href="http://$c$c.metager.de/source/xref/android/2.2.3/frameworks/base/core/java/android/text/SpannableStringBuilder.java"相对=nofollow> 2.2.3源 VS <一href="http://$c$c.metager.de/source/xref/android/4.1.1/frameworks/base/core/java/android/text/SpannableStringBuilder.java"相对=nofollow> 4.1.1源)。日志行是由企图的零长度的字符串中设定的跨度触发。这就是为什么设置这么需要的文字没有(子)部分,选择要避免这个错误,或者由上述技巧或使用:

 安卓textIsSelectable =假
机器人:编辑=假
 

一个投机性更强的解决方案,也许,以确保通过添加字符\ u200b(零非显示空白字符从未有一个的TextView 一个空字符串宽)的每一个你把你的的TextView 弦乐,无论是覆盖的setText (简单地将其添加到年底字符串)在自定义的的TextView 或将它放在你的code发送到的TextView 每串秒。

对于那些谁喜欢钻研的Andr​​oid系统和它的首要部分,根据<一href="http://$c$c.metager.de/source/xref/android/4.1.1/frameworks/base/core/java/android/text/Editable.java"相对=nofollow>这块Android的源它看起来mght可以通过下面的解决这个问题。但是,绝对不能保证它的工作原理。真正勇敢的(鲁莽)可以写一个完整的SpannableStringBuilder自己......

  1. 创建自己的形式 SpannableStringBuilder 中的陷阱条件。这个例子只是静静地停止,而不是停止了一声,按原来的:

     进口android.text.SpannableStringBuilder;
    
    公共类MySpannableStringBuilder扩展SpannableStringBuilder {
        //从SpannableStringBuilder.java拍摄
        私有静态最终诠释MARK = 1;
        私有静态最终诠释点= 2;
        私有静态最终诠释START_MASK = 0XF0;
        私有静态最终诠释END_MASK =为0x0F;
        私有静态最终诠释START_SHIFT = 4;
    
        MySpannableStringBuilder(){
            超();
        }
    
        MySpannableStringBuilder(CharSequence的文字){
            超(文本);
        }
    
        MySpannableStringBuilder(CharSequence的文字,诠释开始,诠释完){
            超(文本,开始,结束);
        }
    
        @覆盖
        公共无效setSpan(对象是什么,诠释开始,诠释年底,诠释标志){
            //确定如果错误将被触发,如果是的话失败默默
            INT flagsStart =(标志和安培; START_MASK)&GT;&GT; START_SHIFT;
            INT flagsEnd =标志和放大器; END_MASK;
            如果(flagsStart ==点和放大器;&安培; flagsEnd == MARK&功放;&功放;启动==结束){
                返回;
            }
    
            //所有的好,所以叫真正的程序
            super.setSpan(什么,flagsStart,为此,flagsEnd);
        }
    }
     

  2. 创建 MyEditableFactory延伸Editable.Factory 键,将其设置为回报您SpannableStringBuilder:

     进口android.text.Editable;
    
    公共类MyEditableFactory扩展Editable.Factory {
        私有静态MyEditableFactory sInstance =新MyEditableFactory();
    
        / **
          *返回此编辑厂。
          * /
        公共静态Editable.Factory的getInstance(){
            返回sInstance;
        }
    
        市民可编辑newEditable(CharSequence的源){
            返回新MySpannableStringBuilder(源);
        }
    }
     

除了写操作系统的定制版本,并把它在手机上,我不知道还有什么是可能的。

所有的改进建议欢迎,以及反馈使用该code在各种操作系统的情况。

I have app start with Splash screen then open listactivity rows, clicking on any row will opens an activity containing a textview, two buttons (one of which opens an infinite gallery, the other opens a custom dialog), and menu items (about, preference, exit).

This app runs perfectly on ginger bread but when tested on a galaxy s3 running jelly bean, it opens normally but when you click on one of the listactivity rows it appears to ignore the click. The log cat on eclipse shows :

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 

However, there is no force close (the listactivity scrolls normally and the menu items work fine and ).

UPDATE:
I noticed something this application: I created it with eclipse since around one month ago with a name lets say (trip) and today testing (trip.apk) on both ginger bread and jelly bean it works perfectly.

But I wanted to change the name from trip to travel and I did not use Refactor. Instead I created a new project with application name called travel but all other things are the same as the previous app trip including classes, res, and when tested with jelly bean shows:

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 

UPDATE 3 :

I SOLVED THE PROBLEM :

i added this line to all TextViews in my app which is :

 android:textIsSelectable="true"

and that line lead to rows ignore the click ,

so i removed it and now both old and new app work fine with both API .

UPDATE 4:

the above phrases related to old issue and already solved ,

THE QUESTION NOW IS :

my application work perfectly with all APIs but when tested with:

galaxy S3 running jelly bean work perfectly also ,

but in eclipse log cat show error :

 SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero  length

without affect application performance , any idea to solve that error .

any explanation will be highly appreciated , thanks.

the code of my 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 for whole list as 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 i = 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 the custom dialog components - text, image and 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 is clicked, close the 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 the custom dialog components - text, image and 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 is clicked, close the 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 the custom dialog components - text, image and 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 is clicked, close the 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 the custom dialog components - text, image and 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 is clicked, close the 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 the
                    // custom dialog components - text, image and 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 is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }
    }

    public void handleClick(View v) {
        // Create an intent to start the new activity.
        Intent intent = new Intent();
        intent.setClass(this, DayGallery.class);
        intent.putExtra("dayname", day);
        startActivity(intent);
    }
}

logcat:

D/AbsListView(14159): Get 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) to 14.306MB for 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) to 16.941MB for 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 a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
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 a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
W/OpenGLRenderer(14159): Shape round rect too large to be rendered into a texture 
(680x12472, max=4096x4096)
W/OpenGLRenderer(14159): Shape round rect too large to be rendered into a texture 
(688x12480, max=4096x4096)
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length
E/SpannableStringBuilder(14159): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero 
length

解决方案

To understand what is happening here, it all starts with a design decision about what a TextView should and shouldn't be. According to the android source for TextView:

/**
 * Displays text to the user and optionally allows them to edit it.  A TextView
 * is a complete text editor, however the basic class is configured to not
 * allow editing; see {@link EditText} for a subclass that configures the text
 * view for editing.

This means that, even if all you're doing is putting a piece of text on the screen, hidden behind that are full text highlight, selection and editing facilities. What has happened here is that a little tweak to resolve an issue in them appears to have interfered with some other functionality, and created some log lines. That this is the case is given more weight by, say, Nexus 7 error "SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length", in which it would seem that on some android versions this situation can be resolved by disabling autocomplete in text (entry) fields:

View.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS );

This could also be done in the XML using the corresponding tags for a TextView:

android:inputType="none"

The lines in question appear to have arrived in Android 4.1 (Jelly Bean), in the setSpan function of SpannableStringBuilder (eg. 2.2.3 source vs 4.1.1 source). The log line is triggered by an attempt to set a span within a string of zero length. This is why setting it so that no (sub) section of the text needs to be selected should avoid this error, either by the above tip or by using:

android:textIsSelectable="false"
android:editable="false"

A more speculative solution maybe to ensure that there is never a blank string in a TextView by adding the character "\u200b" (a non-shown blank character of zero width) to every string you put in your TextViews, either by overriding setText (to simply add it to the end of the string) in a custom TextView or by putting it in your code for every string sent to TextViews.

For those who like delving into the android system and overriding parts of it, according to this piece of android source it looks like it mght be possible to solve the issue by the following. However, there is absolutely no guarantee that it works. The truly brave (foolhardy) can write a complete SpannableStringBuilder for themselves ....

  1. Creating your own form of SpannableStringBuilder which traps the condition. This example simply stops quietly, rather than stopping loudly, as per the original:

    import android.text.SpannableStringBuilder;
    
    public class MySpannableStringBuilder extends SpannableStringBuilder {
        // Taken from 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 the error is going to be triggered, if so fail silently
            int flagsStart = (flags & START_MASK) >> START_SHIFT;
            int flagsEnd = flags & END_MASK;
            if (flagsStart == POINT && flagsEnd == MARK && start == end) {
                return;
            }
    
            // All good, so call the real routine
            super.setSpan(what, flagsStart, end, flagsEnd);
        }
    }
    

  2. Creating MyEditableFactory extends Editable.Factory and setting it to return your SpannableStringBuilder:

    import android.text.Editable;
    
    public class MyEditableFactory extends Editable.Factory {
        private static MyEditableFactory sInstance = new MyEditableFactory();
    
        /**
          * Returns this Editable Factory.
          */
        public static Editable.Factory getInstance() {
            return sInstance;
        }
    
        public Editable newEditable(CharSequence source) {
            return new MySpannableStringBuilder(source);
        }
    }
    

Other than writing a custom version of the OS and putting it on the phone, I'm not sure what else is possible.

All suggestions for improvement welcome, as well as feedback on using this code in various OS situations.

这篇关于Listactivity误差果冻豆运行设备(SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有长度为零)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆