Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search View Rendering Problems in API 22 [duplicate]

We've just updated local Android SDK to new version 22, and we are trying to update also our apps, but it seems to be a problem with SearchView rendering in layout Design view of Android Studio: everytime designer try to render a SearchView element, it throws an exception:

java.lang.NullPointerException   at android.content.res.TypedArray.hasValueOrEmpty(TypedArray.java:845)   at android.widget.SearchView.(SearchView.java:295)   at android.widget.SearchView.(SearchView.java:258)   at android.widget.SearchView.(SearchView.java:254)   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)   at android.view.LayoutInflater.createView(LayoutInflater.java:607)   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)   at android.view.LayoutInflater.inflate(LayoutInflater.java:385)

This occours even if we create a new element from left toolbar in a new layout file. Any idea?

Rendering error

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <SearchView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/searchView" />
</LinearLayout>
like image 699
Davide Avatar asked Apr 16 '26 21:04

Davide


2 Answers

Edit

Change your android version on your designer preview into your current version depend on your Manifest. rendering problem caused your designer preview used higher API level than your current android API level.


It should work

Just change the api 22 to 21 in android xml layout

enter image description here

like image 93
N J Avatar answered Apr 18 '26 12:04

N J


I voted up Davide comments. Error means searchIcon can not be null (why?).

This works to compile at Studio with api 22, but forces you to select an icon. The example is one of 2 defaults at android (none as cool as searchview default), you can always have your custom one...

Here the snippet.

        <SearchView
        android:id="@+id/searchBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:searchIcon="@android:drawable/ic_search_category_default"
        tools:ignore="UnusedAttribute" />
like image 20
Dieglock Avatar answered Apr 18 '26 11:04

Dieglock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!