-1

将它放在 onCreateView 方法中的 DialogFragment 中时出现空指针异常

 AutoCompleteTextView med =(AutoCompleteTextView)getActivity().findViewById(R.id.new_autoCompleteT);
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, item);
 med.setAdapter(adapter);
4

1 回答 1

0

您似乎正在尝试View从关联的Activity. 您应该检查对 的调用getActivity(),也许它返回 null 因为它尚未附加的活动。检查onActivityCreated (Bundle savedInstanceState)方法,从文档

Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. 
于 2012-06-22T19:56:38.097 回答