0

so I'm kinda new to all of this application making.

I'm trying to reach a file using the command InputStream inputStream = openFileInput("files.txt"); and it gives me the error "Cannot resolve methodopenFileInput(java.lang.String)".My file is not saved i assets or in resources, it's saved i whatever place it saves when you just create it in the application.

Questions

  1. Can I read a file in widgets
  2. If so why is this not working?

The function

private void readFiles() throws IOException 
{
    cards.removeAll(cards);
    InputStream inputStream = openFileInput("files.txt");
    if(inputStream != null){
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        int size = Integer.parseInt(bufferedReader.readLine());
        for(int i = 0; i < size; i++){
            card tmp = new card();
            tmp.setAlias(bufferedReader.readLine());
            tmp.setIconID(Integer.parseInt(bufferedReader.readLine()));
            tmp.setId(bufferedReader.readLine());
            tmp.setRemaining(Integer.parseInt(bufferedReader.readLine()));
            tmp.setDescription(bufferedReader.readLine());
            tmp.setPeriodStartDate(bufferedReader.readLine());
            tmp.setPeriodEndDate(bufferedReader.readLine());
            tmp.setPeriodRemaining(Integer.parseInt(bufferedReader.readLine()));
            tmp.setWaitingPeriods(Integer.parseInt(bufferedReader.readLine()));
            tmp.setUnFetched(Integer.parseInt(bufferedReader.readLine()));
            tmp.setNameDescription(bufferedReader.readLine());
            tmp.setCardExpiryDate(bufferedReader.readLine());
            tmp.setCardStatus(bufferedReader.readLine());
            tmp.setDaysUntilCardExpiry(bufferedReader.readLine());
            cards.add(tmp);
        }
        inputStream.close();
    }
}
vipe
  • 39
  • 7
  • [This answer](http://stackoverflow.com/a/17439798/410342) might explain why this isn't working inside a widget. You can't just call `openFileInput()` since it isn't defined in the scope of the Widget class and its subclasses. You'd need to pass the Activity Context into the Widget and call it on the `Context` object (a la `context.openFileInput(...)`). – Shotgun Ninja Nov 17 '15 at 20:59
  • Thank you! Solved the problem :) – vipe Nov 17 '15 at 21:22

0 Answers0