Adding a search bar

0 Reginald Johnson · October 10, 2015
When I put the code to create a search bar in the app I'm building and click run on my phone it says the app has stopped working, but before adding the code, the app worked fine. Can anyone give me some suggestions as I am new to programming?

Post a Reply


Oldest  Newest  Rating
0 Reginald Johnson · October 17, 2015
No I don't know how to debug yet, I just started to learn how to program. How do you know when you're using the right widget? 
0 Gary Whitney · October 17, 2015
It has only been 3 days since my reply and I have found 3 more ways to get halt my program.
1. Today I was following and example in a book and made a style that wasn't compatible with my activity. (Wouldn't even launch)
2. Yesterday I forgot to include the required parameters in an override. (died when I clicked a button)
3. I passed the wrong type of value.

The answer to your question about  the right widget has to do with findViewById()
findViewById looks for the id you defined with the Android:id tag in your xml.

Here is my suggestion.
Reply with more information:
1. Include a screen dump of the error or just copy and paste the first few lines when the log file turns Red.
you  can use the add image icon to paste the screen dump.
2. You say it worked before you  added the search code so include your code using the Add Code icon.
0 Reginald Johnson · October 26, 2015
Sorry for the late response!  Here are screen shots of the code./images/forum/upload/2015-10-26/a71f104bf8556f9a5a1651cdc499cd47.png/images/forum/upload/2015-10-26/ba08c154aaa0e48bcbea1b42f620f988.png/images/forum/upload/2015-10-26/d0b331784ba4b0f3b169824df3f09282.png/images/forum/upload/2015-10-26/b6d20733353ea1af64a672f4b4432c84.png
0 Gary Whitney · October 27, 2015
Thanks for the Screenshots.
First let me say that I haven't used the searchview widget yet, so I read about it on
The searchdialog is used in the Action Bar and the searchview is used in your layout.

There is more you will have to to create a android.intent.action.SEARCH" but you are not there yet right?
You just want your app to not stop working.
So here are somethings I noticed from your screenshots.

1. your app extends AppcompatActivity - ok
2. your manifest declares the app theme with NoActionBar. - but
    your main activity tries to implement  an ActionBar - this seams contradictory to me. Why not  just declare your theme to use an ActionBar? or do you want to use the ActionDialog which goes in the ActionBar?
3. you have the same Toast for all your options in the menu listener.
4. your reference to your searchview finds the id declared in your homelayout.

My suggestion if you want to play with the searchview widget is to keep it simple.
Drop switch from your menu options you don't have anything there unless your menu.xml file has them, which you didn't include in your screen shots. This is probably what is killing your app.
Just use an ActionBar theme if you want an ActionBar.

I hope this helps :)
P.S. I found this during my searching
0 Gary Whitney · October 10, 2015
I have had this error many times.
It is usually a logic error.
The code compiles but  then tries to do something that "doesn't compute".
0 Reginald Johnson · October 12, 2015
Is there a way to fix this to get the app to work?
0 Gary Whitney · October 14, 2015
Do you know how to use the debugger?
You can set a breakpoint before the new code.

Or you can try the old fashion way of commenting out the code you added and selectively adding back a few lines after each run.
Pay particular attention to your references. Ex. Did  you  ref the widget you meant to? If you try to run a method on the wrong type of widget, that won't work.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator