Reputation: 727
I am trying to read a csv file from the android assets folder. I have viewed other posts on this and it seems I have it set up as others do. I have tried this.getAssets()
and passing the context to the method and using context.getAssests()
Here is the code that I am using to read the file. And put the information into a database.
try{
AssetManager mng = getApplicationContext().getAssets();
InputStream is = mng.open("word_types.csv");
CSVReader csv = new CSVReader(new InputStreamReader(is));
String[] s;
while((s = csv.readNext()) != null){
db.addWordType(Integer.parseInt(s[0]), s[1], Integer.parseInt(s[2]));
}
csv.close();
}catch(IOException ioe){
Log.e("File Read Error: ","" + ioe.getMessage());
}
for(int i=1;i<=12 ;i++ )
Log.i(i+" = ", ""+ db.getWordType(i));
Here is what prints out in logcat:
E/File Read Error: (25767): word_types.csv
I/1 = (25767): null
I/2 = (25767): null
I/3 = (25767): null
I/4 = (25767): null
I/5 = (25767): null
I/6 = (25767): null
I/7 = (25767): null
I/8 = (25767): null
I/9 = (25767): null
I/10 = (25767): null
I/11 = (25767): null
I/12 = (25767): null
Upvotes: 2
Views: 2417
Reputation: 727
I realized I had made a stupid mistake. Thank you CommonsWare for telling me about printing out the stacktrace like that. I did not know about adding ioe as a third parameter. After viewing the stacktrace I realized that I spelled the assets directory wrong. I had assests.
Upvotes: 4