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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:28:46+00:00 2026-06-18T10:28:46+00:00

I have to make a program that will ask for the user to enter

  • 0

I have to make a program that will ask for the user to enter 10 names, then sort the names alphabetically, then print each name, how many characters, and how many vowels.
I think I am close but keep getting this error in processing. Can anyone help with this?

`Exception in thread "Animation Thread" java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1217)
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1211)
at java.lang.String.compareToIgnoreCase(String.java:1258)
at test.setup(test.java:35)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:662)`

My code is:

import javax.swing.*;
String names[] = new String[10];
String temp;
String nameInput;
int length;
int vowel = 0;
char ch;
length = 0;
// store user input to array
for (int i = 0; i < names.length; i++) {
  nameInput = JOptionPane.showInputDialog ("Enter a name:");
  names[i] = nameInput;
  length = names[i].length();

// sort into alphabetical order
  for (int j = 0; j < names.length - 1; j++) {
    for (int k = j + 1; k < names.length; k++) {
      if (names[j].compareToIgnoreCase(names[k]) > 0) {
        temp = names[j];
        names[j] = names[k];
        names[k] = temp;
      }
    }
  }
  // count vowels
  char[] characters = nameInput.toCharArray();
  for (int m = 0; m < characters.length; m++) {
    ch = nameInput.charAt(m);

    if ((ch == 'A') || (ch == 'a')
      ||  (ch == 'E') || (ch == 'e')
      ||  (ch == 'I') || (ch == 'i')
      ||  (ch == 'O') || (ch == 'o')
      ||  (ch == 'U') || (ch == 'u')) {
      vowel++;
    }
  }

  System.out.println("Name: " + names[i] + ", Length: " + length + ", Vowels: " + vowel);
  vowel = 0;
}
  • 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-18T10:28:47+00:00Added an answer on June 18, 2026 at 10:28 am

    This is the problem:

    for (int i = 0; i < names.length; i++) {
      nameInput = JOptionPane.showInputDialog ("Enter a name:");
      names[i] = nameInput;
      length = names[i].length();
    
      // sort into alphabetical order
      for (int j = 0; j < names.length - 1; j++) {
        for (int k = j + 1; k < names.length; k++) {
          if (names[j].compareToIgnoreCase(names[k]) > 0) {
    

    You’re trying to sort in the same loop that you’re entering the names.

    So after entering the first name, the first element will be non-null, but all the other array elements will be null references, which is what’s causing the problem.

    I suggest you split this into two separate loops:

    1. Enter all the names
    2. Sort them

    Basically, you need to close your first loop earlier:

    for (int i = 0; i < names.length; i++) {
      // No need to use a separate variable: assign directly into the array
      names[i] = JOptionPane.showInputDialog ("Enter a name:");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a program that will ask a user to enter
I need to write a program, that will ask a user to enter a
Write a Python program that will ask the user to enter a string of
I'm trying to make a C function which will ask the user to enter
I want to make a program in C which will ask the user to
I have been trying, in vain, to make a program that reads text out
I have a Flash program that needs to make url requests to send data
I need to make the program which have one form that contains PNG image
I'm trying to write a program that will take an HTML file and make
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and

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.