“活动”文件中的符号未解析错误

时间:2022-07-13 20:52:22

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:

我正在尝试使用列表视图列出SD卡上的所有音乐文件。在Activity的Java代码中,我收到一个错误,这是我在课堂上使用的方法:

 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 .

Android Studio说无法解析符号示例。

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

但是,当我在XML中明确定义时,这怎么可能呢?这是XML代码:

<?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 !

寻找解决方案!

1 个解决方案

#1


5  

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

不确定它是否能解决问题,但你的xml格式不正确。

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

<符号后面不应该有任何空格:< p>

<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"/>

#1


5  

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

不确定它是否能解决问题,但你的xml格式不正确。

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

<符号后面不应该有任何空格:< p>

<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"/>