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

The Archive Base Latest Questions

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

Here are snippets from my code: class Lines{ int nameMax() throws IOException{ // initialize

  • 0

Here are snippets from my code:

class Lines{
int nameMax() throws IOException{
    // initialize variables
    // These will be the largest number of characters in name
    int namelen = 0;

    //These will be the current word lenght.     
    int namelenx = 0;

    ... 

    while(name != null){
        name = br.readLine();
        namelenx = name.length();

    ...

        if(namelenx > namelen) namelen = namelenx;


    }

    float nameleny = namelen/2; //Divides by 2 to find midpoint

    namelen = Math.round(nameleny); //Value is rounded

    return namelen;
}   
}

I am using BlueJ, and whenever I try to run this it is giving me the error in the title and highlighting namelenx = name.length(); There are String variables for name as it was part of the code I cut out. Helping answers please. Thanks.

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

    It throws NPE when br.readLine() returns null, as you invoke length() on null.
    your while loop should be something like below:

    while((name= br.readLine())!=null){
            namelenx = name.length();
    

    Now, even if bufferedReader returns null on readLine() your while would terminate.

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

Sidebar

Related Questions

Here's the problem -- I have a few thousand small text snippets, anywhere from
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here is a snippet from a Sinatra app where users will be submitting urls.
Let me first put the code snippets here. I am just using the ASP.NET
I want to understand if code snippets are what I am looking for here.
I use UDP Sokckts in my client application. Here are some code snippets: SendIP
Here is a code snippet from Zed Shaw's Learn Python the Hard Way tutorial
In an existing code snippet, I have import sys from code import InteractiveConsole class
I modified this simple countdown timer form here: https://github.com/lunaryorn/snippets/blob/master/qt4/countdown.py as follows. Now I want
Here's a snippet of code I saw on the web and I'm wondering if

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.