Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:32:56+00:00 2026-06-13T00:32:56+00:00

I am wondering does reading files in android only works under onCreate() of an

  • 0

I am wondering does reading files in android only works under onCreate() of an activity?
I having this question because my reading process works when the reading process is in side of onCreate() or in side a method that is called under onCreate.

Following is what I am using for reading a file

try {
            file="";
            InputStream ish =     this.getResources().openRawResource(R.drawable.regular_hero_deck);
            BufferedReader brh = new BufferedReader(new     InputStreamReader(ish));
            if(ish!=null){
                while ((data = brh.readLine()) != null)   {
                    file+=data;
                }
            }
            ish.close();
            regularDeckHero =new Deck<Hero>("heroDeck",file);
        }catch (Exception e){//Catch exception if any
            System.err.println("Error : reading hero deck");}   

Solution: it is the problem with

InputStream ish =     this.getResources().openRawResource(R.drawable.regular_hero_deck);

this.getResources() is doesn’t give what I wanted, the resources you need is the one from your MainActivty pass this resources to this should work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:32:57+00:00Added an answer on June 13, 2026 at 12:32 am

    It works every where, even outside an Activity..

    may be the below line

    InputStream ish =     this.getResources().openRawResource(R.drawable.regular_hero_deck);
    

    causes the problem.. because you use this (current instance which is an Activity)..

    instead by getting application context refrence you can still say

    InputStream ish =     context.getResources().openRawResource(R.drawable.regular_hero_deck);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading about memory management techniques and was wondering: Why does every process
I'm really wondering what this code does: scala> import java.nio.file._ import java.nio.file._ scala> Files.copy(Paths.get(),
I've been reading this but I was just wondering, does Solr have the capability
I'm wondering why does Visual Studio code analysis give a warning with this little
I was wondering how exactly does TCP implement in-order delivery. lets say this is
Motivated by this answer I was wondering what's going on under the curtain if
This may seem a silly question, but having been pondering it for a few
I was wondering what the most efficient way of reading a directory of files
I have been reading the Android documentation and I am wondering if anyone can
I was wondering does anyone know if its possible to open a wifi and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.