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 8904653
In Process

The Archive Base Latest Questions

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

Problem: all I want is to filter or let say search the item on

  • 0

Problem: all I want is to filter or let say search the item on the ListView but I always end up with this error "java.lang.NullPointerException". Please help me solve this problem.

PlayListActivity.java:

package com.name.musicplayer;

import java.util.ArrayList;
import java.util.HashMap;
import com.androidhive.musicplayer.PlayListActivity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class PlayListActivity extends ListActivity {
// Songs list
public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

//list view adapter
ArrayAdapter<String> adapter_l;
// Search EditText
EditText inputSearch;

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

    inputSearch = (EditText) findViewById(R.id.inputSearch);

    ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();

    SongsManager plm = new SongsManager();
    // get all songs from sdcard
    this.songsList = plm.getPlayList();

    // looping through playlist
    for (int i = 0; i < songsList.size(); i++) {
        // creating new HashMap
        HashMap<String, String> song = songsList.get(i);

        // adding HashList to ArrayList
        songsListData.add(song);
    }

    // Adding menuItems to ListView
    ListAdapter adapter = new SimpleAdapter(this, songsListData,
            R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
                    R.id.songTitle });

    setListAdapter(adapter);


    met_play_song_on_list();
    met_search();
}

private void met_play_song_on_list() {
    // TODO Auto-generated method stub
    // selecting single ListView item
            ListView lv = getListView();
            // listening to single listitem click
            lv.setOnItemClickListener(new OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting listitem index
                    int songIndex = position;

                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(),
                            AndroidBuildingMusicPlayerActivity.class);
                    // Sending songIndex to PlayerActivity
                    in.putExtra("songIndex", songIndex);
                    setResult(100, in);
                    // Closing PlayListView
                    finish();
                }
            });
}

private void met_search() {
    // TODO Auto-generated method stub
    /**
     * Enabling Search Filter
     * */

    inputSearch.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            //PlayListActivity.this.adapter_l.getFilter().filter(cs);
        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub

        }

        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            PlayListActivity.this.adapter_l.getFilter().filter(arg0);
        }
    });
}
}

Here is the SongManager.java class:

package com.name.musicplayer;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.name.musicplayer.JSONParser;

public class SongsManager {
// SDCard Path
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();


// url to make request
private static String url = "http://domain.com/android/songlist.php";

// JSON Node names
private static final String TAG_str_song = "str_song";
private static final String TAG_str_song_name = "str_song_name";
private static final String TAG_str_song_path = "str_song_path";

// contacts JSONArray
JSONArray songslist = null;

// Constructor
public SongsManager() {

}

/**
 * Function to read all mp3 files from sdcard and store the details in
 * ArrayList
 * */
public ArrayList<HashMap<String, String>> getPlayList() {

    // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(url);

    try {
        // Getting Array of Contacts
        songslist = json.getJSONArray(TAG_str_song);

        // looping through All Contacts
        for (int i = 0; i < songslist.length(); i++) {
            JSONObject c = songslist.getJSONObject(i);

            // Storing each json item in variable
            String str_song_name = c.getString(TAG_str_song_name);
            String str_song_path = c.getString(TAG_str_song_path);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put("songTitle", (i+1) +". " + str_song_name);
            map.put("songPath", "http://domain.com/" + str_song_path);

            // adding HashList to ArrayList
            songsList.add(map);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return songsList;
}

/**
 * Class to filter files which are having .mp3 extension
 * */
class FileExtensionFilter implements FilenameFilter {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".mp3") || name.endsWith(".MP3"));
    }
}
}
  • 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-15T02:11:19+00:00Added an answer on June 15, 2026 at 2:11 am

    Without seeing the stacktrace with the exception I assume the NullPointerException comes from using the EditText to filter the adapter:

    PlayListActivity.this.adapter_l.getFilter().filter(arg0);
    

    The line above will throw a NullPointerException because the adapter_l is null as you don’t assign it a valid reference anywhere in your code. You should modify the onCreate method like this:

    adapter_l = new SimpleAdapter(this, songsListData,
                R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
                        R.id.songTitle });
    setListAdapter(adapter_l);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stumped all day on this problem. Basically I want to check
Problem: i want to do filter for all webapps. I created a filter for
I have a strange WPF/XAML problem. By default, I want all of the nodes
Problem Hello all! I have this code which takes my jpg image loops through
I periodically get this problem where all of a sudden mako is using old
In other browsers no problem at all. But in chroom when i hover on
The problem I am trying to solve is that I want to check all
Let's say I have a list of values to which I want to apply
Let's say I have a list and a set and I want to do
So first of all I am sorry for asking this question . But the

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.