Error: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
Asked Answered
A

3

10

I got a problem with my android app. I got a button and and event associated , but when I click the first time an error appears

"spans cannot have zero lenght".

. But when I click the second time, the event onclick runs well.. look at my java code:

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    final Button selectAltitude = (Button) findViewById(R.id.buttonAltitude1);
    final Button selectAltitude2 = (Button) findViewById(R.id.buttonAltitude2); 
    
    selectAltitude2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view){
            
                String tempAlt = selectAltitude2.getText().toString();
                selectAltitude2.setText(selectAltitude.getText().toString());
                selectAltitude.setText(tempAlt);
        }
    });
    }

The xml code with the two buttons (a deprecated warning occurs):

 <?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:background="@android:color/black"> 

<Button
        android:id="@+id/buttonAltitude1"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="39dp"
        android:layout_height="42dp"
        android:layout_marginLeft="250dp"
        android:layout_x="257dp"
        android:layout_y="419dp"
        android:background="@drawable/drawable1"
        android:focusableInTouchMode="true"
        android:gravity="center_vertical"
        android:includeFontPadding="false"
        android:linksClickable="true"
        android:minHeight="10dp"
        android:minWidth="64dp"
        android:paddingLeft="10dp"
        android:paddingRight="5dp"
        android:scrollHorizontally="true"
        android:text="@string/button_meters"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        android:textStyle="bold" />
        
        <Button
            android:id="@+id/buttonAltitude2"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="65dp"
            android:layout_height="42dp"
            android:layout_marginLeft="250dp"
            android:layout_x="295dp"
            android:layout_y="419dp"
            android:background="@drawable/drawable2"
            android:clickable="true"
            android:focusableInTouchMode="true"
            android:gravity="center_vertical"
            android:includeFontPadding="false"
            android:linksClickable="true"
            android:minHeight="10dp"
            android:minWidth="64dp"
            android:paddingLeft="15dp"
            android:paddingRight="5dp"
            android:scrollHorizontally="true"
            android:text="@string/button_feet"
            android:textColor="@android:color/black"
            android:textSize="25sp"
            android:textStyle="bold" />

When I click the first time Log cat interacts with:

04-06 20:01:39.865: I/Sensors(6946): sendDelay --- 200000000 04-06

20:01:39.865: D/SensorManager(6946): JNI - sendDelay 04-06

20:01:39.865: I/SensorManager(6946): Set normal delay = true 04-06

20:01:39.890: E/SpannableStringBuilder(6946): SPAN_EXCLUSIVE_EXCLUSIVE

spans cannot have a zero length 04-06 20:01:39.890:

E/SpannableStringBuilder(6946): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot

have a zero length

can you help ne?;)

Audrit answered 5/4, 2013 at 16:45 Comment(3)
Add activity_main.xml code too.Enjambment
Please post a stack trace from LogcatPotsherd
It's updated now :) thanksAudrit
I
21

I have run into the same error entries in LogCat. In my case it's caused by the 3rd party keyboard I am using. When I change it back to Android keyboard, the error entry does not show up any more.

This is the most probable cause of this issue as there is also a bug report for SwiftKey:

http://support.swiftkey.net/forums/116693-2-bug-reports/suggestions/2994580-span-exclusive-exclusive-spans-cannot-have-a-zero-

Income answered 5/4, 2013 at 16:51 Comment(5)
@Carlos Piedade Read this answer and links which I posted here.Income
i'm sorry for the waiting.. I saw your answer, and I can't understand how can I fiz my problem. Did you see the update I made in my post and the LogCat info? thanksAudrit
@CarlosPiedade I saw your updated post. It might i shared the link solve your problem. Read my post carefully.Income
can you explain me how I can I change to the Android keyboard?I can't understand how can I do that change..Audrit
@CarlosPiedade You can try following this guide. However, your default device keyboard might automatically come with SwiftKey (this was the case with my Samsung Galaxy Note 10.1).Felicefelicia
S
0

To try to debug this error, first go to your android terminal / console and execute this command:

ps | grep THE_ERROR_PID_YOU_GET_(IT_IS_A_NUMBER)

then if the output comes out as your app... it is your app causing the error. Try to look for empty Strings that you pass into the layout.

I had this exact same problem and it was my fault as I was passing an empty String into my layout. After changing the "" to " " this error went away.

If you don't get your app from the console output, then it is something else causing it (probably, as others said, the android keyboard)

Saguache answered 8/7, 2014 at 15:1 Comment(0)
P
0

I know I'm a little late. In case someone still needs help with having to click the second time for the the event onclick to run, I removed this:

android:focusableInTouchMode="true"

The onClick event will now work on the first click.

Pug answered 17/6, 2015 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.