Closed savishy closed 8 years ago
I wonder if the crash is happening in this line (inside TokenAutoComplete)
@SuppressWarnings("unchecked cast")
@Override
protected CharSequence convertSelectionToString(Object object) {
selectedObject = (T) object;
It looks like a cast to the generic type (T) which in my case is Ingredient
.
EDIT: No, it was a cast from String to Ingredient, not the other way around.
It looks like this is something related to http://www.studytonight.com/java/serialization-and-deserialization.php
Figured it out. (facepalm)
background
The TokenCompletionTextView
(see source) needs to be initialized inside an Activity (obviously).
In my code, I am doing the init as follows.
ArrayAdapter
inside AddRecipeActivity
which stores the list of ingredients. I do the initialization within the onCreate
method as
@Override
protected void onCreate(Bundle savedInstanceState) {
IngredientsCompletionView completionView;
....
....
//initialize TokenAutocompleteView
completionView = (IngredientsCompletionView) findViewById(R.id.searchView);
ArrayAdapter<String> adp = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, new String[]{"ing1","ing2","ing3"});
completionView.setAdapter(adp);
completionView.setTokenListener(this);
The ArrayAdapter
is initialized as String
but it should be initialized as ArrayAdapter<Ingredient>
for this thing to work.
This issue is verified fixed.
Commit d65c6517a5d59eb73e0b5c5ac393373e1687ffb6:
This was written to fix #1 . However it crashes when an ingredient is selected.