2014-09-04 10 views
3

Может кто-нибудь объяснить это? У меня есть arrayList со строками. Я использую! Arraylist.contain, чтобы убедиться, что я не добавляю дубликатов. В коде ниже я показываю все, что в ArrayList, а затем проверить, если же значение не существует в ArrayList с помощью !arraylist.containArrayList .contain дает странный вывод

public ArrayList<String> getIsiXhosaRecordings(ArrayList<String> must_download, ArrayList<String> all_filenames) 
{ 
    database = getReadableDatabase(); 

    for(int x = 0; x < all_filenames.size(); x++) 
    { 
     System.out.println("All files: >>>"+all_filenames.get(x)+"<<<"); 
    } 

    String[] table_names = {"Voice_exercise", "Lesson_exercise"}; 
    for(int x = 0; x < table_names.length; x++) 
    { 
     String SQL = "SELECT * FROM "+table_names[x]; 
     Cursor cursor = database.rawQuery(SQL, null); 

     while(cursor.moveToNext()) 
     { 
      String audio_isixhosa = cursor.getString(cursor.getColumnIndex("audio_isixhosa")); 
      if(!all_filenames.contains(audio_isixhosa)); 
      { 
       System.out.println("Audio file: >>>"+audio_isixhosa+"<<<"); 
      } 
     } 
    } 
    return must_download; 
} 

И в LogCat:

09-04 15:30:40.188: D/dalvikvm(14202): GC_CONCURRENT freed 65K, 9% free 9852K/10759K, paused 2ms+2ms, total 24ms 
09-04 15:30:40.188: W/SQLiteConnectionPool(14202): A SQLiteConnection object for database '/data/data/com.example.molo/databases/molo.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed. 
09-04 15:30:40.298: I/System.out(14202): All files: >>>clock.jpg<<< 
09-04 15:30:40.298: I/System.out(14202): All files: >>>confident.jpg<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>correct.png<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>correct.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>crowd.jpg<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e001.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e003.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e004.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e005.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e007.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e008.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e009.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e010.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e011.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e012.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e013.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e014.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e015.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e016.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e017.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e018.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e019.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e020.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e021.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e022.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>e023.wav<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>goodbye.jpg<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>greeting.jpg<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>how.jpg<<< 
09-04 15:30:40.308: I/System.out(14202): All files: >>>howareyou.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>images<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>incorrect.png<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>incorrect.wav<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>kioskmode<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>lock.png<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>map.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>molo.db<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>morning.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>pe.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>question.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>question2.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>sounds<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>stranger.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>thembi.jpg<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>unlock.png<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>webkit<<< 
09-04 15:30:40.318: I/System.out(14202): All files: >>>what.jpg<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>who.jpg<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>why.jpg<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>world.jpg<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x001.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x002.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x003.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x004.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x005.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x006.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x007.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x008.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x009.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x010.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x011.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x012.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x013.wav<<< 
09-04 15:30:40.328: I/System.out(14202): All files: >>>x014.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x015.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x016.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x017.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x018.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x019.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x020.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x021.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x022.wav<<< 
09-04 15:30:40.338: I/System.out(14202): All files: >>>x023.wav<<< 
09-04 15:30:40.338: I/System.out(14202): Audio file: >>>x001.wav<<< 
09-04 15:30:40.338: I/System.out(14202): Audio file: >>>x004.wav<<< 
09-04 15:30:40.338: I/System.out(14202): Audio file: >>>x008.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x005.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x010.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x019.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x020.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x021.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x001.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x002.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x003.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x004.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x005.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x006.wav<<< 
09-04 15:30:40.348: I/System.out(14202): Audio file: >>>x007.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x008.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x009.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x010.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x012.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x013.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x014.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x015.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x016.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x017.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x018.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x022.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>x023.wav<<< 
09-04 15:30:40.358: I/System.out(14202): Audio file: >>>baboon.wav<<< 
09-04 15:35:40.068: W/IInputConnectionWrapper(14202): getSelectedText on inactive InputConnection 
09-04 15:35:40.068: W/IInputConnectionWrapper(14202): setComposingText on inactive InputConnection 
09-04 15:35:40.068: W/IInputConnectionWrapper(14202): getExtractedText on inactive InputConnection 

Я добавил «>> > "и" < < < ", чтобы убедиться, что я не пропускаю пустые места, а arrayList must_download будет использоваться позже. Почему одинаковые значения приводятся вall_filenames.contains, а также!all_filenames.conatins? Я пробовал делать все, начиная с .toString(), но получаю те же результаты. Я также использовал аналогичные методы для похожих имен файлов, которые отлично работают.

Благодаря

ответ

13

точка с запятой после if завершается в заявлении

if(!all_filenames.contains(audio_isixhosa)); 
{ // <-- new block separate from if. 

и поэтому тело пустой блок. Удалите точку с запятой.

if(!all_filenames.contains(audio_isixhosa)) { 
+2

Этого было трудно обнаружить! – luanjot

+0

@ Elliott - хороший! – BatScream

+2

Спасибо, это может быть просто глупая вещь, которую я когда-либо делал ... –

Смежные вопросы