为什么是这个代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_assets, container, false);
List<String> states = new ArrayList<String>();
String abs = "AL AK AZ AR CA CO CT DE FL GA HI ID IL IN "
+ "IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK "
+ "OR PA RI SC SD TN TX UT VT VA WA WV WI WY";
for (String parts : abs.split(" ")) {
states.add(parts);
}
EditText store = (EditText) view.findViewById(R.id.store_input_ID);
EditText phone = (EditText) view.findViewById(R.id.phone_input_ID);
EditText address = (EditText) view.findViewById(R.id.address_input_ID);
EditText city = (EditText) view.findViewById(R.id.city_input_ID);
EditText zip = (EditText) view.findViewById(R.id.zip_input_ID);
Spinner myStates = (Spinner) view.findViewById(R.id.bi_spinner);
ArrayAdapter<String> aa = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item, states);
myStates.setAdapter(aa);
return view;
}
加载时崩溃并在此行给我一个空指针异常
myStates.setAdapter(aa);
我已经尝试将我声明的位置移动Array
到ArrayList
上面我首先膨胀布局的位置,在 之外onCreate
,并且在我找到所有内容之后直接移动,Views
但它仍然给出空指针异常。
我似乎无法弄清楚,我知道我错过了一些明显的东西。