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

  • Home
  • SEARCH
  • 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 7083327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:51+00:00 2026-05-28T07:09:51+00:00

I am trying to load a file into a Map with a method as

  • 0

I am trying to load a file into a Map with a method as below:

private static Map<String,Integer> indexVocabulary;
public static Map<String,Integer> getVocabularyFromFile() throws IOException
{
    FileInputStream fstream = new FileInputStream(VOCABULARY_FILE);
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));      
    String line;
    while( (line = br.readLine()) != null )
    {
        LOG.debug(line);
        String[] kv = line.split(" ");
        LOG.debug(kv[0]);
        LOG.debug(Integer.toString(Integer.parseInt(kv[1])));


        indexVocabulary.put(kv[0], Integer.parseInt(kv[1]));
    }
    return indexVocabulary;
}

I can see output from line‘also from kv[0],kv[1] and Integer.parseInt(kv[1]) However I get a NullPointerException on the line indexVocabulary.put(kv[0], Integer.parseInt(kv[1])); Does anyone know what is wrong with this method?

  • 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-05-28T07:09:52+00:00Added an answer on May 28, 2026 at 7:09 am

    You don’t initialize indexVocabulary, so it’s null.

    Change

    private static Map<String,Integer> indexVocabulary;
    

    to

    private static Map<String,Integer> indexVocabulary = new HashMap<String,Integer>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to dynamically load a KML file into a map depending on
I'm trying to load a file into a string. Here is the code I'm
I was trying to load a data file into mysql table using LOAD DATA
I am trying to figure out an eazy way to load CSV file into
I am trying to achieve a situation where i load a file into the
All, I am trying to load up a bmp file into a GLubyte array
I'm trying to load Gravatars into Flash. Luckily, they provided a crossdomain.xml file at
I'm trying to put a 3D model into a PDF file. When I load
I am trying to load a data file into mysql table using LOAD DATA
I'm trying to load a swf file into my main swf. Everything looks fine

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.