0

I have this line of code:

String[] projection = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ARTIST, 
         MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA, 
         MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.DURATION};

Which should work, but eclipse is giving me an error: "Syntax error on token ";", , expected"

Here is the top half of my code:

public class Main extends Activity implements OnClickListener
{
    ListView lv;
    static final int check = 1111;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lv = (ListView) findViewById(R.id.listView1);
        Button b = (Button) findViewById(R.id.button1);
        b.setOnClickListener(this);
    }
    Cursor cursor;
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

    String[] projection = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DURATION};

    cursor = this.managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);

    private List<String> songs = new ArrayList<String>();
    while(cursor.moveToNext())
    {
        songs.add(cursor.getString(0) + "||" + cursor.getString(1) + "||" +   cursor.getString(2) + "||" +   cursor.getString(3) + "||" +  cursor.getString(4) + "||" +  cursor.getString(5));
    }
7
  • 3
    That's not where the problem is from. Show us more (before it and after). Commented May 18, 2013 at 14:06
  • 1
    @MarounMaroun: beat me too it! Commented May 18, 2013 at 14:06
  • 1
    Your while loop is in no method. Commented May 18, 2013 at 14:08
  • Can you please paste the complete code, not only the top half and also including the imports? And this is not your real code, you are calling methods in the body of your class. That won't work. Commented May 18, 2013 at 14:08
  • Moving the while loop to a method still does not fix the string issue... Commented May 18, 2013 at 14:09

1 Answer 1

6

The next line of code:

cursor = this.managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);

needs to be in a method or constructor (or init block of some kind). It can't just hang out loose in the class as you currently have it. Note that as per @MarounMaroun, you have other code with the same problem -- your next while loop for instance. Or you could declare cursor at this point, though this can be risky since you can't catch exceptions if you do it this way if there is a risk of this occurring.

Consider organizing your code a bit better by putting all variable declarations together (I usually put them at the top), then constructors, then methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.