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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:17:55+00:00 2026-06-09T07:17:55+00:00

I am writing small game and I need to read off text file, write

  • 0

I am writing small game and I need to read off text file, write it into array and then print array. My class for reading and returning array looks like this:

import java.io.*;
import java.util.*;

public class WordsList {

    public String[] wordsList;


    public void readFile() throws Exception{

        FileInputStream in = new FileInputStream("test.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        NumberOfLines read = new NumberOfLines();
        int n = read.getLineCount();

        String strLine;
        wordsList = new String[n];   

        for (int j = 0; j < wordsList.length; j++){
        wordsList[j] = br.readLine();

        }
        in.close();
    }

    public String[] returnsWordList(){
        return wordsList;
    }
}

And in main class I have this:

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        WordsList words = new WordsList();
        System.out.println(words.returnsWordList());
    }

}

It returns null value rather than words…
What did I do wrong? Any ideas?

  • 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-09T07:17:57+00:00Added an answer on June 9, 2026 at 7:17 am

    What did I do wrong? Any ideas?

    You failed to call readFile() anywhere in your code. Change your main method to:

    WordsList words = new WordsList();
    words.readFile();
    System.out.println(words.returnsWordList());
    

    and it will probably print out a non-null reference. It won’t be a useful representation, because arrays don’t override toString. If you want to see that actual contents, you’d want:

    System.out.println(Arrays.toString(words.returnsWordList()));
    

    There are various other ways in which your code is still far from great, but that should at least get you started.

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

Sidebar

Related Questions

I am writing a small Android game using a SurfaceView class. The outline of
I am writing a small RPG game engine with Lua/love2d, and I need to
Inspired by Brent Yorgey's adventure game , I've been writing a small text based
I am writing a small game by using cocos2d. It is a shooting game.
I'm writing a small game for Windows Phone 7. It's a vocabulary based game,
I am writing a small game for Android. The game is drawn on a
I have am writing a small game using Applet. I want to be able
I am currently considering writing a small game. It is essentially a map where
I have writing a small shooting game in cocos2d. Winning the game is to
A little background: I'm writing a small word based maze game starting with a

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.