I'm trying to parse a local json file called "category.json" but when I call the file I get an "Unhandled IO Exception" error. I have created the category.json file as well.
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView= inflater.inflate(R.layout.content_menu, container, false);
String jsonArray="category.json";
Gson gson = new Gson();
List<Category> list = gson.fromJson(new FileReader(jsonArray), new TypeToken<List<Category>>(){}.getType());
RecyclerView myrv = (RecyclerView)rootView.findViewById(R.id.recyclerview_id);
RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(getActivity(),list);
myrv.setLayoutManager(new GridLayoutManager(getContext(), 3));
myrv.setAdapter(myAdapter);
return rootView;
}
I even tried using the AssetManager I still get the same error
AssetManager assetManager =getContext().getAssets();
InputStream is = assetManager.open("category.json");