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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:17:56+00:00 2026-06-08T23:17:56+00:00

I am trying to use stringTokenizer method for reading a 2D array stored in

  • 0

I am trying to use stringTokenizer method for reading a 2D array stored in a file in the format..

1 1
1 1 

the code is…

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<n;i++)
                for(int j=0;j<n;j++){
                    StringTokenizer tok = new StringTokenizer(in.readLine());
                    t[i][j]=Integer.parseInt(tok.nextToken());
                }

when i run this i am getting the java.lang.NullPointerException error.However if i use this in file

1 1 1 1

the code works!

why is it happening?

  • 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-08T23:17:58+00:00Added an answer on June 8, 2026 at 11:17 pm

    By having your StringTokenizer object declaration/instantiation in the nested for loop the StringTokenizer object doesn’t exist outside of the scope of the nested loop. So what this really does is just repeat the nested loop and so everything you read is horizontal only. If you move the StringTokenizer outside of the nested loop and inside of the parent loop it will still be in scope for the nested loop. That should fix your problem.

    Move:
    StringTokenizer tok = new StringTokenizer(in.readLine()); above your nested loop.

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

Sidebar

Related Questions

I'm trying to import a CSV file into an array that I can use
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying use Lift and CalendarMonthView widget to build a appointment system. CalendarMonthView works
I'm trying use the Sum method in a lambda expression for a comparison, but
I am trying use the new server side plug-in feature for TFS 2010. (I
I'm working with VS2010 express on Win7 (64 bit) and I'm trying use System.ServiceModel
I am relatively new to CMake, and I'm trying use the boost asio library
I am trying use Process.StartInfo() to launch (with elevated privileges) an exe file I

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.