I have a search bar at the top of a listview and there is an action button which toggles the visibility of the search bar...
The search bar is shown correctly, however when I hide it the app crashes. This is the code to toggle the view...
/**
* Show / Hide the search box
*/
private void toggleSearch()
{
//in the instance there are not customers...a crash will occur when searching
if(customers.length > 0)
{
if(searchVisible)//hide the search bar
{
searchFrame.setVisibility(View.GONE);
Log.i("SEARCH", "HIDDEN");
searchVisible = false;
Log.i("SEARCH", "BOOLEAN SET");
resetList();
Log.i("SEARCH", "LIST RESET?");
}
else//show the search bar
{
searchFrame.setVisibility(View.VISIBLE);
searchVisible = true;
}
}
}
and here is the LogCat output...
11-18 11:33:22.483: I/SEARCH(1591): SHOWN
11-18 11:33:22.493: D/audio_hw_primary(183): select_devices: out_snd_device(4: headphones) in_snd_device(0: )
11-18 11:33:22.753: D/audio_hw_primary(183): out_set_parameters: enter: usecase(0: deep-buffer-playback) kvpairs: routing=4
11-18 11:33:24.473: I/SEARCH(1591): HIDDEN
11-18 11:33:24.473: I/SEARCH(1591): BOOLEAN SET
11-18 11:33:24.473: I/SEARCH(1591): LIST RESET?
11-18 11:33:24.473: D/AndroidRuntime(1591): Shutting down VM
11-18 11:33:24.473: E/AndroidRuntime(1591): FATAL EXCEPTION: main
11-18 11:33:24.473: E/AndroidRuntime(1591): Process: evans.louis.firstdroid, PID: 1591
11-18 11:33:24.473: E/AndroidRuntime(1591): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:392)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.ListView.onMeasure(ListView.java:1175)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.View.measure(View.java:16458)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.View.measure(View.java:16458)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.View.measure(View.java:16458)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-18 11:33:24.473: E/AndroidRuntime(1591): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.View.measure(View.java:16458)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-18 11:33:24.473: E/AndroidRuntime(1591): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2289)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.View.measure(View.java:16458)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1914)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1111)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1293)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.Choreographer.doFrame(Choreographer.java:532)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.os.Handler.handleCallback(Handler.java:733)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.os.Handler.dispatchMessage(Handler.java:95)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.os.Looper.loop(Looper.java:137)
11-18 11:33:24.473: E/AndroidRuntime(1591): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-18 11:33:24.473: E/AndroidRuntime(1591): at java.lang.reflect.Method.invoke(Native Method)
11-18 11:33:24.473: E/AndroidRuntime(1591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-18 11:33:24.473: E/AndroidRuntime(1591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-18 11:33:24.483: W/ActivityManager(609): Force finishing activity evans.louis.firstdroid/com.firsthosted.firstdroid.CustomerList
any ideas?
Thanks
EDIT: here is resetList() as requested
/**
* Revert the ListView to it's original order
*/
private void resetList()
{
try
{
adapter = new ArrayAdapter<String>(this, R.layout.listview_container, R.id.name, customers);
lv.setAdapter(adapter);
}
catch(Exception e)
{
Library.errorHandler("resetList", e);
}
}
Just spotted my mistake in resetList()
I have...
adapter = new ArrayAdapter<String>(this, R.layout.listview_container, R.id.name, customers);
and it should have been ...
adapter = new ArrayAdapter<String>(this, R.layout.listview_text, R.id.name, customers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With