Это код я взять из данных JSON, я передать его в массивview.findViewById для getchildAt списке следует() обратного NullPointer
public class CheckboxMCQ extends Fragment {
private View rootview;
private View footerView;
private View header;
private ListView questionAnswerList;
CheckboxAdapter checkboxAdapter;
ArrayList<checkboxmodel> arraystoreanswer;
ArrayList<checkboxmodel> arraytemppreselect;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootview = inflater.inflate(R.layout.fragment_checkbox_mcq, container, false);
questionAnswerList = (ListView) rootview.findViewById(R.id.question_answer_list);
footerView = ((LayoutInflater) getParentFragment().getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null,false);
header = ((LayoutInflater) getParentFragment().getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.header, null,false);
questionAnswerList.addFooterView(footerView);
questionAnswerList.addHeaderView(header);
arraystoreanswer = new ArrayList<checkboxmodel>();
arraytemppreselect = new ArrayList<checkboxmodel>();
checkboxAdapter = new CheckboxAdapter(getActivity(), arraystoreanswer,CheckboxMCQ.this , ss_id);
questionAnswerList.setAdapter(checkboxAdapter);
return rootview;
}
/*preselect operation*/
public void preselectoperation(final String uid, final String sf_id, final String ssid, final String sqid, final String order) {
class AsyncTaskRunner extends AsyncTask<String,String,JSONObject> {
String response;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... params) {
urlLink url = new urlLink();
JSONObject jsonObject = url.checkboxpreselectrow(uid, sf_id, ssid, sqid);
return jsonObject;
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
try {
response = jsonObject.getString("success");
if (response.equals("1"))
{
JSONArray job = jsonObject.getJSONArray("record");
for (int i = 0; i<job.length(); i++){
JSONObject jsonOb = job.getJSONObject(i);
arraytemppreselect.add(new checkboxmodel(jsonOb.getString("ans_id")));
}
for (int i=0; i < arraystoreanswer.size(); i++){
for (int j=0; j < arraytemppreselect.size(); j++){
if((arraystoreanswer.get(i).getAnswerid().equals(arraytemppreselect.get(j).getAnswerid()))){
//do something for equals
Log.i("same value",arraystoreanswer.get(i).getAnswerid());
// Log.i("position value",""+ i);
changebackgroundpreselect(i+1);
}
}
}
}
else {
}
} catch (JSONException e1) {
e1.printStackTrace();
}
}
}
new AsyncTaskRunner().execute();
}
public void changebackgroundpreselect(int position){
// if (i == position){
View view = questionAnswerList.getChildAt(position);
Log.i("getChildAt",""+ position);
CheckBox cb = (CheckBox) view.findViewById(R.id.answer_content);
cb.setBackgroundResource(R.drawable.checkboxbuttonselected);
// }
}
}
Это моя пустота функция, я знаю, основная проблема здесь, но не знаю, как решить эту проблему, то ListView GetView возвращают нулевое положение у меня есть получить его, но вернуться NullPointer на здесь:
CheckBox cb = (CheckBox) view.findViewById(R.id.answer_content);
Извините за мой английский сломаны, спасибо мой журнал об ошибке enter image description here
добавьте полный Java и код ошибки ... – W4R10CK
@ W4R10CK я есть обновить журнал ошибок, но я думаю, что проблема начинается с видом view = questionAnswerList.getChildAt (позиция); здесь –
Пожалуйста, добавьте полный код java –