0

アプリに保存した文字列を取得して印刷しようとしています。何らかの理由でアプリがクラッシュします。私たちを手伝ってくれますか?:)

ListView list;
String[] listC, filenames;
String entry;
int files, i;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pastbets);

    list = (ListView) findViewById(R.id.list);
    listC = new String[filenames.length/2];
    Prepare();

    ArrayAdapter<String> filenameAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listC);
    list.setAdapter(filenameAdapter);
}

private void Prepare() {
    filenames = getApplicationContext().fileList();
    files = filenames.length/2;
    for(i=0; i<files; i++) {
        entry = openFile(filenames[2*i])+" - "+openFile(filenames[2*i+1]);
        listC[i] = entry;
    }
}

「openFile」機能は大丈夫だと思いますが...

private String openFile(String selectFile) {
    String file = "";
    FileInputStream fis;

    try {
        fis = openFileInput(selectFile);
        byte[] input = new byte[fis.available()];
        while(fis.read(input) != -1){
            file += new String(input);
        }
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}
4

1 に答える 1