After looking fo ther error at least at the fourm and found only answers that speak about 3rd party device keyborad or somthing that caused it(Samsung devices at least)(Iam using my one plus One). Ive setted a timer for 10 seconds and every time it reached it 3rd time of runnig (i refresh the activity) i got that error SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length.
TimerAttack class code:
@SuppressLint("NewApi")
public class TimeAttack extends Activity implements AnimationListener {
String pic;//תמונה של הדגל
Button answer1;//תשובות
Button answer2;
Button answer3;
Button answer4;
Button hint;
TextView guess;
TextView numOfGuess;
TextView score;
TextView scorenum;
TextView textViewTime;
MediaPlayer mpHint;
MediaPlayer mpNext;
MediaPlayer mpWrong;
Animation animationfadein;
Animation animationfadeout;
String fn;
Guesses G;
Score s;
Timer t;
Button [] b = new Button[4];
DatabaseHandler db = new DatabaseHandler(this);
List<String>WrongAnswers=new ArrayList<String>();
int countG=0;//count Guesses
int countA=0;//count right Answers
int countQ=0;//count Questions
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
score =(TextView)findViewById(R.id.score);
scorenum =(TextView)findViewById(R.id.scorenum);
scorenum.setText(String.valueOf(s.score));
guess =(TextView)findViewById(R.id.guesses);
numOfGuess=(TextView)findViewById(R.id.numOfGuesses);
numOfGuess.setText(String.valueOf(Guesses.numOfGuesses));
textViewTime = (TextView) findViewById(R.id.textViewTime);
hint =(Button)findViewById(R.id.hint);
hint.setOnClickListener(hintOnClickListener);
mpHint = MediaPlayer.create(this,R.raw.hint_sound);
mpNext = MediaPlayer.create(this, R.raw.next_flag);
mpWrong = MediaPlayer.create(this, R.raw.wrong_answer);
animationfadein = AnimationUtils.loadAnimation(this, R.anim.fade_in);
animationfadeout = AnimationUtils.loadAnimation(this, R.anim.fade_out);
textViewTime.setText(t.time);
final CounterClass timer = new CounterClass(11000, 1000);
timer.start();
Flags f = new Flags();
Random r = new Random();//הדגל שיבחר לשאלה
int num = r.nextInt(160);//Up
f = db.getFlag(num);//הצגת הדגל הרנדומלי שיצא
fn = f.getName().toString();
pic = f.getImage().toString();
pic_view(pic);//מעבר לפונקציה להשמת התמונה של הדגל במשחק
//מערך ארבע כפתורים כנגד ארבע תשובות
b[0] = (Button)findViewById(R.id.button1);
b[1] = (Button)findViewById(R.id.button2);
b[2] = (Button)findViewById(R.id.button3);
b[3] = (Button)findViewById(R.id.button4);
List<String>Answers=new ArrayList<String>();//מערך תשובות
Answers.add(f.getName().toString());//הוספת התשובה הנכונה
for(int i=1;i<4;i++)
{
num = r.nextInt(200);
String valToAdd1 = db.getFlag(num).getName().toString();
if(!Answers.contains(valToAdd1)){
WrongAnswers.add(valToAdd1);
Answers.add(valToAdd1);
}
}
Collections.shuffle(Answers);//ערבוב התשובות
for(int i=0;i<Answers.size();i++)
{
b[i].setText(Answers.get(i));//השמת התשובות מהמהערך למערך הכפתורים
b[i].startAnimation(animationfadein);
}
}//end of OnCreat
public boolean onOptionsItemSelected(MenuItem item){//actionbar activity
Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
return true;
}
@SuppressLint("NewApi")
public void resetQuiz()
{
countQ++;
recreate();
}
private OnClickListener hintOnClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpHint.start();
/*if(Guesses.numOfGuesses==1)
{
G.setNumOfGuesses(3);
finish();//כאשר מספר הניחושים
return;
}
else*/
G.numOfGuesses++;
numOfGuess.setText(String.valueOf(Guesses.numOfGuesses));
int invisblecount=0;
for(int i=0;i<b.length;i++){
if(invisblecount<2){
String buttonText = b[i].getText().toString();
if(buttonText.equals(WrongAnswers.get(0))||buttonText.equals(WrongAnswers.get(1)))
{
b[i].startAnimation(animationfadeout);
b[i].setVisibility(View.INVISIBLE);
invisblecount++;
}
}
}
}
};
public void check(View v)
{
Log.d("yes", fn);
Button b = (Button)v;
String text = b.getText().toString();
if(text.equals(fn))
{
mpNext.start();
s.score+=5;
resetQuiz();
}
else
{
mpWrong.start();
Guesses.numOfGuesses++;
countG=Guesses.numOfGuesses;
/*if(Guesses.numOfGuesses==1)
{
//G.setNumOfGuesses(3);
//finish();//כאשר מספר הניחושים
return;
}else
Guesses.numOfGuesses--;*/
if(s.score>0)
s.score-=5;
scorenum.setText(String.valueOf(s.score));
numOfGuess.setText(String.valueOf(Guesses.numOfGuesses));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
private void pic_view(String pic2) {
// TODO Auto-generated method stub
//גישה לדגל לפי שמו וייבוא התמונה
Log.d("Result from pic function " , pic2);
ImageView imageView = (ImageView)findViewById(R.id.imageView1);
String uri ="@drawable/";
uri += pic2;
int imageResource = getResources().getIdentifier(uri, pic2, getPackageName());//הצוות התמונה
Drawable res= getResources().getDrawable(imageResource);//ציור התמונה
imageView.setImageDrawable(res);
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Animatoin Stoped", Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public class CounterClass extends CountDownTimer {
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
long millis = millisUntilFinished;
String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
System.out.println(hms);
textViewTime.setText(hms);
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
Log.d("Time", "More" + textViewTime.getText().toString());
Toast toast = Toast.makeText(getApplicationContext(), "Time's up Lets see what you made so far...", Toast.LENGTH_SHORT);
toast.show();
Intent en = new Intent(TimeAttack.this,Person.class);
String extra = scorenum.getText().toString();
en.putExtra("Score",extra);
startActivity(en);
}
}
}
stacktrace:
04-26 11:26:15.590: I/System.out(5670): 00:00:08
04-26 11:26:15.610: I/System.out(5670): 00:00:03
04-26 11:26:16.590: I/System.out(5670): 00:00:07
04-26 11:26:16.620: I/System.out(5670): 00:00:02
04-26 11:26:17.590: I/System.out(5670): 00:00:06
04-26 11:26:17.630: I/System.out(5670): 00:00:01
04-26 11:26:18.590: I/System.out(5670): 00:00:05
04-26 11:26:19.130: D/yes(5670): Finland
04-26 11:26:19.320: D/into(5670): com.example.flagsgame.Flags@42cc7998
04-26 11:26:19.320: D/into(5670): 147
04-26 11:26:19.320: D/Result from pic function(5670): palau
04-26 11:26:19.420: D/into(5670): com.example.flagsgame.Flags@428a6720
04-26 11:26:19.420: D/into(5670): 119
04-26 11:26:19.460: D/into(5670): com.example.flagsgame.Flags@42d8f3d0
04-26 11:26:19.460: D/into(5670): 37
04-26 11:26:19.490: D/into(5670): com.example.flagsgame.Flags@42b7ff38
04-26 11:26:19.490: D/into(5670): 183
04-26 11:26:19.510: E/MediaPlayer(5670): Should have subtitle controller already set
04-26 11:26:19.510: E/MediaPlayer(5670): Should have subtitle controller already set
04-26 11:26:19.510: E/MediaPlayer(5670): Should have subtitle controller already set
04-26 11:26:19.510: I/System.out(5670): 00:00:10
04-26 11:26:19.510: D/Time(5670): More00:00:01
04-26 11:26:19.530: I/Timeline(5670): Timeline: Activity_launch_request id:com.example.flagsgame time:36376629
04-26 11:26:19.710: W/MediaPlayer-JNI(5670): MediaPlayer finalized without being released
04-26 11:26:19.710: W/MediaPlayer-JNI(5670): MediaPlayer finalized without being released
04-26 11:26:19.720: W/MediaPlayer-JNI(5670): MediaPlayer finalized without being released
04-26 11:26:19.720: W/Bundle(5670): Key Score expected Integer but value was a java.lang.String. The default value 0 was returned.
04-26 11:26:19.730: W/Bundle(5670): Attempt to cast generated internal exception:
04-26 11:26:19.730: W/Bundle(5670): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
04-26 11:26:19.730: W/Bundle(5670): at android.os.Bundle.getInt(Bundle.java:1000)
04-26 11:26:19.730: W/Bundle(5670): at android.content.Intent.getIntExtra(Intent.java:4620)
04-26 11:26:19.730: W/Bundle(5670): at com.example.flagsgame.Person.onCreate(Person.java:40)
04-26 11:26:19.730: W/Bundle(5670): at android.app.Activity.performCreate(Activity.java:5231)
04-26 11:26:19.730: W/Bundle(5670): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-26 11:26:19.730: W/Bundle(5670): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
04-26 11:26:19.730: W/Bundle(5670): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
04-26 11:26:19.730: W/Bundle(5670): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-26 11:26:19.730: W/Bundle(5670): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
04-26 11:26:19.730: W/Bundle(5670): at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 11:26:19.730: W/Bundle(5670): at android.os.Looper.loop(Looper.java:136)
04-26 11:26:19.730: W/Bundle(5670): at android.app.ActivityThread.main(ActivityThread.java:5146)
04-26 11:26:19.730: W/Bundle(5670): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 11:26:19.730: W/Bundle(5670): at java.lang.reflect.Method.invoke(Method.java:515)
04-26 11:26:19.730: W/Bundle(5670): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
04-26 11:26:19.730: W/Bundle(5670): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
04-26 11:26:19.730: W/Bundle(5670): at dalvik.system.NativeStart.main(Native Method)
04-26 11:26:19.800: I/System.out(5670): 00:00:04
04-26 11:26:19.910: I/Timeline(5670): Timeline: Activity_idle id: android.os.BinderProxy@42b40b18 time:36377008
04-26 11:26:19.920: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:19.920: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:19.930: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:19.930: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:20.510: I/System.out(5670): 00:00:09
04-26 11:26:20.800: I/System.out(5670): 00:00:03
04-26 11:26:21.510: I/System.out(5670): 00:00:08
04-26 11:26:21.800: I/System.out(5670): 00:00:02
04-26 11:26:22.510: I/System.out(5670): 00:00:07
04-26 11:26:22.800: I/System.out(5670): 00:00:01
04-26 11:26:23.510: I/System.out(5670): 00:00:06
04-26 11:26:24.050: D/Time(5670): More00:00:01
04-26 11:26:24.060: I/Timeline(5670): Timeline: Activity_launch_request id:com.example.flagsgame time:36381154
04-26 11:26:24.150: W/Bundle(5670): Key Score expected Integer but value was a java.lang.String. The default value 0 was returned.
04-26 11:26:24.150: W/Bundle(5670): Attempt to cast generated internal exception:
04-26 11:26:24.150: W/Bundle(5670): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
04-26 11:26:24.150: W/Bundle(5670): at android.os.Bundle.getInt(Bundle.java:1000)
04-26 11:26:24.150: W/Bundle(5670): at android.content.Intent.getIntExtra(Intent.java:4620)
04-26 11:26:24.150: W/Bundle(5670): at com.example.flagsgame.Person.onCreate(Person.java:40)
04-26 11:26:24.150: W/Bundle(5670): at android.app.Activity.performCreate(Activity.java:5231)
04-26 11:26:24.150: W/Bundle(5670): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-26 11:26:24.150: W/Bundle(5670): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
04-26 11:26:24.150: W/Bundle(5670): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
04-26 11:26:24.150: W/Bundle(5670): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-26 11:26:24.150: W/Bundle(5670): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
04-26 11:26:24.150: W/Bundle(5670): at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 11:26:24.150: W/Bundle(5670): at android.os.Looper.loop(Looper.java:136)
04-26 11:26:24.150: W/Bundle(5670): at android.app.ActivityThread.main(ActivityThread.java:5146)
04-26 11:26:24.150: W/Bundle(5670): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 11:26:24.150: W/Bundle(5670): at java.lang.reflect.Method.invoke(Method.java:515)
04-26 11:26:24.150: W/Bundle(5670): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
04-26 11:26:24.150: W/Bundle(5670): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
04-26 11:26:24.150: W/Bundle(5670): at dalvik.system.NativeStart.main(Native Method)
04-26 11:26:24.270: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:24.270: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:24.270: I/Timeline(5670): Timeline: Activity_idle id: android.os.BinderProxy@426f66b0 time:36381361
04-26 11:26:24.520: I/System.out(5670): 00:00:05
04-26 11:26:25.520: I/System.out(5670): 00:00:04
04-26 11:26:26.520: I/System.out(5670): 00:00:03
04-26 11:26:27.520: I/System.out(5670): 00:00:02
04-26 11:26:28.520: I/System.out(5670): 00:00:01
04-26 11:26:30.240: D/Time(5670): More00:00:01
04-26 11:26:30.250: I/Timeline(5670): Timeline: Activity_launch_request id:com.example.flagsgame time:36387346
04-26 11:26:30.320: W/Bundle(5670): Key Score expected Integer but value was a java.lang.String. The default value 0 was returned.
04-26 11:26:30.320: W/Bundle(5670): Attempt to cast generated internal exception:
04-26 11:26:30.320: W/Bundle(5670): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
04-26 11:26:30.320: W/Bundle(5670): at android.os.Bundle.getInt(Bundle.java:1000)
04-26 11:26:30.320: W/Bundle(5670): at android.content.Intent.getIntExtra(Intent.java:4620)
04-26 11:26:30.320: W/Bundle(5670): at com.example.flagsgame.Person.onCreate(Person.java:40)
04-26 11:26:30.320: W/Bundle(5670): at android.app.Activity.performCreate(Activity.java:5231)
04-26 11:26:30.320: W/Bundle(5670): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-26 11:26:30.320: W/Bundle(5670): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
04-26 11:26:30.320: W/Bundle(5670): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
04-26 11:26:30.320: W/Bundle(5670): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-26 11:26:30.320: W/Bundle(5670): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
04-26 11:26:30.320: W/Bundle(5670): at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 11:26:30.320: W/Bundle(5670): at android.os.Looper.loop(Looper.java:136)
04-26 11:26:30.320: W/Bundle(5670): at android.app.ActivityThread.main(ActivityThread.java:5146)
04-26 11:26:30.320: W/Bundle(5670): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 11:26:30.320: W/Bundle(5670): at java.lang.reflect.Method.invoke(Method.java:515)
04-26 11:26:30.320: W/Bundle(5670): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
04-26 11:26:30.320: W/Bundle(5670): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
04-26 11:26:30.320: W/Bundle(5670): at dalvik.system.NativeStart.main(Native Method)
04-26 11:26:30.370: I/Timeline(5670): Timeline: Activity_idle id: android.os.BinderProxy@42b6b638 time:36387461
04-26 11:26:30.370: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:26:30.370: E/SpannableStringBuilder(5670): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
04-26 11:27:03.740: W/IInputConnectionWrapper(5670): getExtractedText on inactive InputConnection
04-26 11:27:03.740: W/IInputConnectionWrapper(5670): getTextBeforeCursor on inactive InputConnection
04-26 11:27:03.740: W/IInputConnectionWrapper(5670): getSelectedText on inactive InputConnection
04-26 11:27:03.740: W/IInputConnectionWrapper(5670): getTextAfterCursor on inactive InputConnection
as you can see the timer are still runnig after the error i got. Error: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length