I need to call a method in which I parse the JSON objects and set the values I sets values in TextFields and button values, I created fragments but after creating the fragments how will I change the text field values
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
//Switch to different layout accordingly
switch (getArguments().getInt(ARG_SECTION_NUMBER))
{
case 1: {
rootView = inflater.inflate(R.layout.fragment_main, container, false);
break;
}
case 2: {
rootView = inflater.inflate(R.layout.fragment_receipt, container, false);
break;
}
case 3: {
rootView = inflater.inflate(R.layout.fragment_totals, container, false);
break;
}
case 4: {
rootView = inflater.inflate(R.layout.fragment_keyboard, container, false);
break;
}
case 5: {
rootView = inflater.inflate(R.layout.fragment_keylock, container, false);
break;
}
}
return rootView;
}
}
I tried to call the method in onStart
but onStart method is been called first before the onCreateView
and hence I get null pointer exception when I am assigning the value :
@Override
public void onStart() {
super.onStart();
parseJsonResponse(response_message);
}
In the parseJsonResponse() method, I sets the value
String UIFooter = ResponseHeaderObject.getString("FOOTER");
//Set Header Display
headerTextView =(TextView) findViewById(R.id.headerTextView);
headerTextView.setText(UIHeader);
here is the error from logcat:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.mpos.kits.smartpos.PosMainActivity.parseJsonResponse(PosMainActivity.java:366)