Skip to content Skip to sidebar Skip to footer

Android Prorgram Crashes When I Attempt To Gettext() From An Autocompletetext

I am trying to build an android app that allows you to input text, and will then transfer the text to the main screen. It allows me to build the autocomplete with no issue, but whe

Solution 1:

Use team1input = (AutoCompleteTextView) view.findViewById(R.id.autoCompleteTeam1) in the onCreateView() method and delete the similar line in the onClick() method.

(Assuming you have the AutoCompleteTextView with autoCompleteTeam1 id defined in the team_score_layout.xml layout file.)

Solution 2:

When you call findViewById() under a view class it finds child views of that class.

When the onClick is triggered, View v passed into onClick() is the button. If the AutoCompleteView you are trying to retrieve is not a child of that button then calling v.findViewById() will give you NullPointerException, since the view does not exist under the button's children tree.

Solution 3:

Just replace

team1input=(AutoCompleteTextView) v.findViewById(R.id.autoCompleteTeam1);

with

team1input=(AutoCompleteTextView) view.findViewById(R.id.autoCompleteTeam1);

Post a Comment for "Android Prorgram Crashes When I Attempt To Gettext() From An Autocompletetext"