Results 1 to 1 of 1
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Why is Android's SearchView's ImageView (with id=search_mag_icon) returning null

    The default SearchView has a search icon in the search hint when it is expanded. I want to remove this icon from the hint.

    Why is Android's SearchView's ImageView (with id=search_mag_icon) returning null-0iqyn.png

    So I saw this answer on SO. It gives the following solution in onCreate():

    Java Code:
    int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
    ImageView magImage = (ImageView) searchView.findViewById(magId);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    Looking at the xml code of Android's search_view.xml here, this solution does make complete sense, but I am getting a NullPointerException at te 6th line in the following snippet:

    Java Code:
    SearchView searchView = (SearchView) findViewById(R.id.searchActivity_searchView);
            int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
            Log.i(TAG, "magId > "+ magId);
            ImageView magImage = (ImageView) searchView.findViewById(magId);
            Log.i(TAG, "magImage > "+ magImage);
            magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    and before the exception, it prints:

    Java Code:
    08-07 14:13:15.740: I/SearchActivity(2548): magId > 16909188
    08-07 14:13:15.740: I/SearchActivity(2548): magImage > null
    So what is the reason of this? Why on earth is it returning Null. what should I do about this?
    Last edited by Zarah; 08-07-2015 at 12:32 PM.

Similar Threads

  1. Replies: 1
    Last Post: 08-07-2014, 03:35 AM
  2. string array returning null pointer.. any hints?
    By natdizzle in forum New To Java
    Replies: 6
    Last Post: 07-22-2013, 06:07 AM
  3. Keeps returning null....
    By Julian in forum New To Java
    Replies: 17
    Last Post: 05-28-2011, 09:12 PM
  4. Keeps returning null
    By ribbs2521 in forum New To Java
    Replies: 7
    Last Post: 02-23-2009, 02:25 AM
  5. String returning null value
    By impact in forum New To Java
    Replies: 7
    Last Post: 08-03-2008, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •