Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:26:18+00:00 2026-06-10T02:26:18+00:00

I am new to Android, I need a path to fulfill my requirements. In

  • 0

I am new to Android, I need a path to fulfill my requirements. In my application I need to provide an option for the user to select their playlist from the application. Is this possible?, please confirm.

I tried this with the following sample code, in the following code I tried to get the files from sd card and display them in list view. When I try to run the application I got force close. Could you please look into this and suggest me if I am doing anything wrong.

My test class.

public class TestMediaActivity extends Activity {
/** Called when the activity is first created. */

private static final String MEDIA_PATH = new String("/sdcard/");
private List<String> songs = new ArrayList<String>();
private MediaPlayer mp = new MediaPlayer();
private int currentPosition = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    updateSongList();
}
public void updateSongList() 
{
    System.out.println("In the updateSongList");
    File home = new File(MEDIA_PATH);
    if (home.listFiles(new Mp3Filter()).length > 0) 
    {
        System.out.println("\n In the condition length>0");
            for (File file : home.listFiles(new Mp3Filter())) {
                    songs.add(file.getName());
            }

            setListAdapter( new ArrayAdapter<String>(this,R.layout.test_item, songs));
    }

}

private void setListAdapter(ArrayAdapter<String> arrayAdapter) {
    // TODO Auto-generated method stub
    System.out.println("In the setListAdapter");
}
protected void onListItemClick(ListView l, View v, int position, long id)
{
    currentPosition = position;
    playSong(MEDIA_PATH + songs.get(position));
}
private void playSong(String songPath) {
    try {

            mp.reset();
            mp.setDataSource(songPath);
            mp.prepare();
            mp.start();

            // Setup listener so next song starts automatically
            mp.setOnCompletionListener(new OnCompletionListener() {

                    public void onCompletion(MediaPlayer arg0) {
                            nextSong();
                    }

            });

    } catch (IOException e) {
            Log.v(getString(R.string.app_name), e.getMessage());
    }
}
private void nextSong() {
    if (++currentPosition >= songs.size()) {
        // Last song, just reset currentPosition
        currentPosition = 0;
} else {
        // Play next song
        playSong(MEDIA_PATH + songs.get(currentPosition));
}
}


}

And supporting class is ,

public class Mp3Filter implements FilenameFilter 
{

@Override
public boolean accept(File dir, String filename) {
    // TODO Auto-generated method stub
    System.out.println("In the Mp3Filter");
    return (filename.endsWith(".mp3"));
   }

}

And the error in the log cat is….

 08-15 14:49:35.800: E/AndroidRuntime(31871): FATAL EXCEPTION: main
 08-15 14:49:35.800: E/AndroidRuntime(31871): java.lang.RuntimeException: Unable to       start activity     ComponentInfo{com.vsoft.TestMedia/com.vsoft.TestMedia.TestMediaActivity}:  java.lang.NullPointerException
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread.access$2300(ActivityThread.java:135)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.os.Looper.loop(Looper.java:143)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread.main(ActivityThread.java:4914)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at java.lang.reflect.Method.invokeNative(Native Method)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at java.lang.reflect.Method.invoke(Method.java:521)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at dalvik.system.NativeStart.main(Native Method)
08-15 14:49:35.800: E/AndroidRuntime(31871): Caused by: java.lang.NullPointerException
08-15 14:49:35.800: E/AndroidRuntime(31871):    at  com.vsoft.TestMedia.TestMediaActivity.updateSongList(TestMediaActivity.java:36)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at com.vsoft.TestMedia.TestMediaActivity.onCreate(TestMediaActivity.java:29)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
08-15 14:49:35.800: E/AndroidRuntime(31871):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
08-15 14:49:35.800: E/AndroidRuntime(31871):    ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:26:19+00:00Added an answer on June 10, 2026 at 2:26 am

    It’s definitely possible. You’ll probably want to use a ListView to display the songs using checkable list items. Then hook the ListView up to a SimpleAdapter that you’ve written. The Adapter will need to fetch the song titles from the SD card (or wherever you’re keeping them), and then provide the ListView with the appropriate list items.

    EDIT

    File home = new File(MEDIA_PATH);
    

    is the problem. home is null. The reason it’s null is because the file isn’t found. You shouldn’t use /sdcard/ to access the SD card because the SD card directory is device-dependent. What you want is:

    File sdCard = Environment.getExternalStorageDirectory();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android and need help on this. I have two views
I am new to android application development. I need a solution for setting random
I need an Android application which should be able to fetch data from the
I am new to Android i need to implement buttons having the size of
Hello i am new in android and i really need help with something. I
I am new in Android. Now I need EditText which should be no more
I'm new To android ecosystem. Do I really need to install all the SDK
My android app project need to add a new function of saving the click
Hai i am new bie to Android. i need to check the network connection
I'm making an Android app where the user can download files from a FTP-server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.