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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:42:57+00:00 2026-06-12T22:42:57+00:00

I have declared two ArrayLists in my main class. One is an ArrayList of

  • 0

I have declared two ArrayLists in my main class. One is an ArrayList of Routine objects, the other a String array of Routine names. Everytime a routine is constructed, that Routine name as well as being stored in the routine is stored in the Names arrayList.

    static ArrayList <Routine> routineArrayList = new ArrayList <Routine> ();
    static ArrayList <String> Names = new ArrayList <String> ();                    

I have created a JList and use the String Names arrayList to populate it..

    list = new JList(Names.toArray());

All is well, I can select a name and the corresponding Routine is chosen.

The PROBLEM, is each Routine, has it’s own ArrayList of Names.

I want to be able to use the selected Routine and populate a JList with the Names INSIDE that Routine. This is what I was trying..

    currentRoutine = routineArrayList.get(intChoice);
    ...
    list = new JList(currentRoutine.Names.toArray());  ******** PROBLEM LINE

System.out.println(currentRoutine.Names.toArray()) gives exactly the same NullPointerException.

It’s been grating on me for a while, any help would be sincerely appreciated likewise if any more information is required I will try my best to provide it.

EDIT

Thanks for your answers, It turns out the primary problem was that the names array inside each Routine object hadn’t been initalized correctly. However, the problem is still there.

'System.out.println("Choice: " + currentRoutine.names.get(0)); // Or get(x) 

and

'System.out.println("Choice: " + currentRoutine.names.toString() 

both give exactly what they should. The complete names array or element
Note: ‘System.out.println(“Choice: ” + currentRoutine.names.toArray() gives the address details etc.

However, when I try

'list = new JList(currentRoutine.names.toArray());' 

I get the same NullPointerException?

Cheers

  • 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-12T22:42:59+00:00Added an answer on June 12, 2026 at 10:42 pm

    The method ArrayList<String>.toArray() should never throw a NullPointerException, so the problem here is almost certainly that either currentRoutine or currentRoutine.Names is null. You need to examine the code where you populate routineArrayList, making sure that all of its elements are non-null and have non-null Names fields.

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

Sidebar

Related Questions

I have two domains declared in my app. class Posts { String title String
I have declared two variables (one global and other local) in a simple C
I have declared two string buffers like, private StringBuffer buf = new StringBuffer(1024); private
I have two methods declared public void MethodA(object o, Action<string> action) { } public
I have the following as two ways to declare a two dimensional String array.
I have two questions. I know it is possible to declare class objects in
I have declared my two dimensional array like this. But getting an error due
I have two classes declared in C# code: public class A { public static
hi all i have an arraylist and array in an activity and have two
I have two classes declared like this: class Object1 { protected ulong guid; protected

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.