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 9238731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:49:49+00:00 2026-06-18T07:49:49+00:00

I am on my way through the Beginning Android Games book by Mario Zechner

  • 0

I am on my way through the “Beginning Android Games” book by Mario Zechner I’m glad I picked it up but I am now running into an issue with one of the “Tests” he requires users to code early on in the book. Not that I am against coding them I would rather know what I am doing than to do a half cocked job and it not work out to well when I get further along.

So AssetManager does not seem to want to load my file.

    AssetManager am = getAssets();
    InputStream inputStream = null;
    try {
        am.open("assets/texts/hello.txt");
        String text = loadTextFile(inputStream);
        tv.setText(text);
    } catch (IOException e) {
        tv.setText("Could not Load file");
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                tv.setText("Could not close file");
            }
        }
    }
}

By all standards I should be able to just use the link: “texts/hello.txt” but every time I do it shoots an NPE at me. So I am forced to use the full link. Using the full link allows the program to run it just fails to load up my text document as per instructions it tells me “Could not load file”

Figured I would nip this issue in the bud now so it does not become a major issue later on.

  • 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-18T07:49:50+00:00Added an answer on June 18, 2026 at 7:49 am

    Change you code as :

     AssetManager am = getAssets();
        InputStream inputStream = null;
        try {
    
             inputStream= am.open("texts/hello.txt"); //<<<<
            String text = loadTextFile(inputStream);
            tv.setText(text);
        } catch (IOException e) {
    
        // your code here
    

    because you are passing null inputStream to loadTextFile method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi so I am working through this book called Beginning Android Games because and
I'm working my way through APress's Beginning Android 2 and I've made it all
I'm working my way through Agile Web Development with Rails and am running into
I'm working my way through the Apress book Beginning Zend Framework - and am
am working my way through the Beginning iPad Development Apress book and have noticed
I am new to cakephp and have been working through the Apress book Beginning
I am new to Objective-C and trying to make my way through a book.
I've been going through a beginning Python book, and I've been trying to write
I've been slowly working my way through the examples in Beginning iPhone Development and
I'm currently working my way through Beginning C# Programming, and have hit a problem

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.