Saturday, 15 March 2014

java - If statement being skipped during execution -



java - If statement being skipped during execution -

this question has reply here:

how compare strings in java? 23 answers

i having problem piece of code. if statement on line 6 beingness ignored during execution. have stepped through code @ point , value of variable file[position] "subjects.dat". however, skipping on steps in , going related else statement. ideas why??

dialogbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { if (markcomplete.ischecked()) { string todelete; string[] files = filelist(); if (files[position] == "subjects.dat") { //the error occurs @ line todelete = files[position + 1]; boolean deleted = deletefile(todelete); if (deleted) { dialog.dismiss(); } else { // nil } } else { todelete = files[position]; boolean deleted = deletefile(todelete); if (deleted) { dialog.dismiss(); } else { //do nil } } } }

thanks!

you need utilize .equals() compare actual value of 2 strings - otherwise you're checking if they're same object.

if (files[position].equals("subjects.dat")) { // stuff }

java android eclipse

No comments:

Post a Comment