New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error in adding Suggestions to search view #169
Comments
Did you place the MSV XML in your layout? Also, did you correctly get the reference using Can you share your layout and more of your code? |
here is xml
Here is Java file. public class SearchActivty extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar search_toolbar;
@BindView(R.id.searchView) MaterialSearchView searchView;
FireStoreLoader fireStoreLoader;
String mQuery = null;
GridLayoutManager gridLayoutManager;
RecyclerViewAdapter recyclerViewAdapter;
boolean dataAvailable = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
ButterKnife.bind(this);
setSupportActionBar(search_toolbar);
getSupportActionBar().setTitle(null);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
searchView.openSearch();
fireStoreLoader = new FireStoreLoader(SearchActivty.this);
fireStoreLoader.getWordsList();
}
}, 300);
searchViewText();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_search){
searchView.openSearch();
}
return true;
}
private void searchViewText(){
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mQuery = query;
Log.i("SearchActivty",mQuery);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
@Override
public void onBackPressed() {
if (searchView.isOpen()){
searchView.closeSearch();
}else{
super.onBackPressed();
}
}
public void addSuggestions(List<String> words){
List<String> newWords = new ArrayList<>();
newWords.add("one");
newWords.add("two");
searchView.addSuggestions(newWords);
} |
When exactly are you calling Also, I see you're using Butter Knife. Can you add a breakpoint after the |
Hello, I am trying to add suggestions from |
Here I call
This is FireStoreLoader class. Here I use Firebase Firestore to fetch data. `public void getWordsList(){
|
I checked that search view is not null. |
Use your debugger again and check if MSV is |
That was the problem. Thanks for the help. |
You're welcome! |
This is my code.
List<String> newWords = new ArrayList<>(); newWords.add("one"); newWords.add("two"); searchView.addSuggestions(newWords);
This is error that I am getting.
java.lang.NullPointerException: Attempt to invoke virtual method 'void br.com.mauker.materialsearchview.MaterialSearchView.addSuggestions(java.util.List)' on a null object reference
The text was updated successfully, but these errors were encountered: