I want to show string (parsed json file) on textview at fragment.
I started project with navigation drawer activity.
parsing is succeeded but
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)'
error occurred
How can I fix it?
MainAcitvity.java
TextView tv=(TextView)findViewById(R.id.text_slideshow);
StringBuilder sb=new StringBuilder();
String json = null;
        try {
            InputStream is = getAssets().open("tour.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
            Log.i("TEST", "afterfileio");
            JSONParser parser=new JSONParser();
            JSONObject jsonObject= (JSONObject) parser.parse(json);
            JSONObject jsonObject1=(JSONObject)jsonObject.get("facilityConveInfo");
            JSONArray jsonArray = (JSONArray) jsonObject1.get("row");
            Log.i("TEST", ""+jsonArray.size() + "");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject subJsonObject = (JSONObject) jsonArray.get(i);
                String FACILITY_NM =subJsonObject.get("FACILITY_NM").toString(); 
                sb.append(FACILITY_NM);
            }
            tv.setText(sb.toString());
fragment_slideshow.xml
<TextView
    android:id="@+id/text_slideshow"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:textAlignment="center"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
SlideFragment.java
public class SlideshowFragment extends Fragment {
    private SlideshowViewModel slideshowViewModel;
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        slideshowViewModel =
                ViewModelProviders.of(this).get(SlideshowViewModel.class);
        View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
        final TextView textView = root.findViewById(R.id.text_slideshow);
        slideshowViewModel.getText().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });
    return root;
 
     
    