• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help with SearchView

Vectron

Lurker
Apr 19, 2017
4
0
I have been working on a project for my school. I am creating an app that will have the school map broken into four different sections and a home page. I am using a drawer menu navigation view for that and it works (attached file titled HHS).

I have tried adding a materialsearchview to the code but when ever I run the code/app on the emulator the app just crashes. I believe that everything is put in correctly but something might be conflicting that I don't have the knowledge for experience to figure out/know. I have attached the not working code with the materialsearchview (attached file titled HHS1).

Any help would be greatly appreciated.
Thanks,Vectron
 

Attachments

  • HHS.zip
    33.9 MB · Views: 73
  • HHS1.zip
    30.4 MB · Views: 94
Hi and welcome to Android Forums.
In order to help you, we would ideally like to see the stack trace from your app when it crashed. This can be found in the Logcat view of Android Studio, and will look something like this

https://developer.android.com/studio/debug/stacktraces.html

Attaching all the source is not that helpful, but hopefully the stack trace will help to focus on the problem area.

Did you write this code? If this is a school project, aimed at teaching you about software development, then part of that process is debugging your code. You would be doing yourself a great favour by learning how to run your app in debug mode. Some useful information is given here

https://androidforums.com/threads/please-read-me-before-posting.987318/
 
Upvote 0
Hi!
Thanks for the first bit of help. the stack trace is attached. For clarification, I am doing this on my own. This isn't a school project or anything, I am choosing to make an app that I think will help the school. Our school can be very confusing especially for people who have never been in it before. Therefore I am making this app with the map built in with room numbers so they can find room they want. I am also trying to implement the material search view so they can search for the room they want and it will show up on the screen, but it is only making the app crash.
Thanks,
Vectron
 

Attachments

  • stack trace.txt
    0 bytes · Views: 43
Upvote 0
I couldn't open your zip files on my system, but looking at the stack trace, you have a NullPointerException, which is causing the app to crash

Code:
04-20 06:13:04.143 2381-2381/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.example.cgeli.hhsfinal, PID: 2381
                                                 java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.MenuItem.setOnMenuItemClickListener(android.view.MenuItem$OnMenuItemClickListener)' on a null object reference
                                                     at com.miguelcatalan.materialsearchview.MaterialSearchView.setMenuItem(MaterialSearchView.java:470)
                                                     at com.example.cgeli.hhsfinal.MainActivity.onCreateOptionsMenu(MainActivity.java:144)
                                                     at android.app.Activity.onCreatePanelMenu(Activity.java:3142)
                                                     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:362)
                                                     at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:98)

So the place you should be focusing on is line 144 in MainActivity. Your MenuItem appears to be null.
If you would like to post the specific part of the code here in the thread, I can take a closer look, but as I say, your zip files are inaccessible for me.
 
  • Like
Reactions: touringhaggis
Upvote 0
Here is the code. Line 144 is bolded
Code:
 [USER=1021285]@override[/USER]
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        actionBarDrawerToggle.syncState();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.drawer_menu, menu);
        MenuItem item = menu.findItem(R.id.action_search);
       searchView.setMenuItem(item); (line 144)

        return true;
    }

    [USER=1021285]@override[/USER]
    public void onBackPressed() {
        if (searchView.isSearchOpen()) {
            searchView.closeSearch();
        } else {
            super.onBackPressed();
        }
    }
}
 
Last edited by a moderator:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones