I’m trying to open a JSON file from the assets folder with an InputStream variable but I get FileNotFoundExeption. The file is there and the path is correct. I’ve looked allover SO but anything that I have found here does not work. Any ideas to what I have wrong and how to correct it (with code please)??
From within the calling activity:
String uri = "file:///android_asset/html/json/regulatory_list.json";
args.putString("KEY_URL", uri);
In the Fragment:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle args = this.getArguments();
String URL = args.getString(KEY_URL);
new GetJSONTask().execute(URL);
}
class GetJSONTask extends AsyncTask<String, Integer, String> {
protected String doInBackground(String... arg0) {
String uri = arg0[0];
InputStream is = null;
if (uri.contains("http") == true) {// Run from URL
try {. . .
} else {
try {. . .
InputStream jsonFile = getActivity().getAssets().open(uri);
Reader reader = new BufferedReader(new InputStreamReader(jsonFile, "UTF-8"));
. . .
}
. . .
I think your file uri is not formatted properly for what you are trying to do.
try changing this:
to this: