2

I am making a MP3 player Android App. I want to start another activity from a ListView click that opens up the artist directory to show the songs from that one artist. I based my code off of the [Android tutorial][1].

This below is in my onCreate in ArtistList.java

    ListView lv = getListView();
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v,int position, long id) {

            Intent intent = new Intent(getApplicationContext(), SongList.class);

            String artistSongPath = artistsList.get(position).get("artistPath");//gets artist SDcard path

            System.out.println("artistSongPath = " + artistSongPath); //prints out correct path

            intent.putExtra("A_S_PATH", artistSongPath); //puts the artistSongPath static A_S_Path

            startActivity(intent); //start the intent
        }
    });

At the top of my ArtistList.java I have

    public final static String A_S_PATH = "wecode.mp3playerapp.MESSAGE";

And in my SongList.java

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.song_list);

    Intent intent = getIntent();
    String path = intent.getStringExtra(ArtistList.A_S_PATH) + "/";
    System.out.println(path);
    try {
        File fp = new File(path);
        findArtistSongs(fp);
    }catch(NullPointerException npe){
        System.out.println("Could not find path.");
    }

}

A_S_Path is null and I am not getting into my catch. Please help! This is my first app!!

Ella
  • 27
  • 4

2 Answers2

0

change this

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.song_list);

    Intent intent = getIntent();
    String path = intent.getStringExtra("A_S_PATH") + "/"; //here is the line that I changed
    System.out.println(path);
    try {
        File fp = new File(path);
        findArtistSongs(fp);
    }catch(NullPointerException npe){
        System.out.println("Could not find path.");
    }
Charaf Eddine Mechalikh
  • 1,248
  • 2
  • 10
  • 20
0

In your ArtistList.java you have:

intent.putExtra("A_S_PATH", artistSongPath);

But in SongList.java, you have:

String path = intent.getStringExtra(ArtistList.A_S_PATH) + "/";

Have you noticed the "A_S_PATH" is different from ArtistList.A_S_PATH you have defined?

Alvis
  • 109
  • 3
  • 13