OBX
OBX

Reputation: 6114

Symbol not resolved error in Activity file

I am trying to list all the music files on the SD card using List view. And in the Java code for the Activity , I get an error, Here is the method I use in class:

 private void init_phone_music_grid() {
    System.gc();
    String[] proj = { MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.DISPLAY_NAME,
            MediaStore.Video.Media.SIZE };
    musiccursor = 
managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            proj, null, null, null);
    count = musiccursor.getCount();
    musiclist = (ListView)findViewById(R.id.sample);
    musiclist.setAdapter(new MusicAdapter(getApplicationContext()));

    musiclist.setOnItemClickListener(musicgridlistener);
    mMediaPlayer = new MediaPlayer();
}

Now here is the simple trouble,

musiclist = (ListView)findViewById(R.id.sample);

Android Studio Says cannot resolve symbol sample .

But how is that possible when I ve clearly defined that in XML? Here is the XML code:

<?xml version="1.0" encoding="utf-8"?>

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
< ListView
    android:id="@+id/sample"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout>

Looking for a solution !

Upvotes: 3

Views: 94

Answers (1)

Simas
Simas

Reputation: 44118

Not sure if it will fix the problem but your xml is malformed.

There shouldn't be any spaces after the < sign:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
    android:id="@+id/sample"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

Upvotes: 5

Related Questions