简体   繁体   中英

Null exception in android 4.1 but working in 4.2

Well I have this in xml

<Spinner
android:id="@+id/spinnerLanguages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />

and In Fragment code file

I have inflated in oncreate

viewInflate = inflater.inflate(R.layout.fragment_search, null);

and

spinnerLanguages = (Spinner) viewInflate.findViewById(R.id.spinnerLanguages);

String[] items1 = new String[] {"lang1", "lang2", "lang3","lang4"};

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getActivity(), android.R.layout.simple_spinner_item, items1);
spinnerLanguages.setAdapter(adapter);

But i am getting Null exception in this line

spinnerLanguages.setAdapter(adapter);

in jellybean(4.1) but it is working fine in 4.2+

How can i solve this problem?

Thank you.

您可能在layout-vx目录中提供了不同版本的布局文件fragment_search.xml :检查您的layour目录中存在多少fragment_search.xml例如,在layout-v17与layout或layout-v16内部 )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM