Symbol not resolved error in Activity file

I am trying to list all music files on an SD card using List view. And in the Java code for the Activity, I get an error, Here is the method I am using in the 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's a simple problem,

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

      

Android Studio Says cannot resolve symbol sample

.

But how is this possible when I have clearly defined it 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!

+3


source to share


1 answer


Not sure if it will fix the problem, but your XML is wrong.

<

There should be no 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"/>

      

+5


source







All Articles