2

我正在尝试从 android assets 文件夹中读取一个 csv 文件。我已经查看了有关此的其他帖子,似乎我已经像其他人一样设置了它。我已经尝试this.getAssets()将上下文传递给方法并使用context.getAssests()Here is the code 我用来读取文件的代码。并将信息存入数据库。

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));

以下是在 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
4

1 回答 1

4

我意识到我犯了一个愚蠢的错误。感谢CommonsWare告诉我关于打印出这样的堆栈跟踪。我不知道将 ioe 添加为第三个参数。查看堆栈跟踪后,我意识到我拼写错误的资产目录。我有评估。

于 2013-03-21T19:03:04.087 回答