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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:36:29+00:00 2026-06-06T13:36:29+00:00

I have constructed a class to mimic a C# struct: public class Favourite {

  • 0

I have constructed a class to mimic a C# struct:

public class Favourite {
    protected  String favName;
    protected  String favText;
    protected String favDelay;
    protected GeoPoint favPoint;
    protected Uri favUri;
}

I want to create an array of this class:

Favourite[] fav;

When I try to access this array:

fav[s].favName = bufr;

I get a NullPointerException. bufr does contain data. I have tracked it down to accessing the array as the following code:

fav[s].favName = "";

also produces a NullPointerException.

I have searched high and low for some indication as to whether or not what I am doing is allowed but cannot find anything.

I suppose my questions are:

Are you allowed to create an array of a class object?
If so, how do you refer to that array?

I know I could do this using five separate arrays of the variables but I feel that putting them into a class gives a better structure and is more elegant (I like elegance).

  • 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-06T13:36:31+00:00Added an answer on June 6, 2026 at 1:36 pm

    The problem is that fav[s] is null.

    I don’t know about C#, but in Java, you have to initialize the elements of the array individually; you can’t just declare the array and get it automatically filled.

    You’re going to have to loop through fav and fill it with new Favourite objects.

    Either assign fav[s] = new Favourite() the first time you use fav[s], or initialize it all at once by doing

    for (int i = 0; i < fav.length; i++) {
      fav[s] = new Favourite();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a varargs constructor like this : public class Sentence { public String[]
I have constructed a struct in a C++ class, Lets sat it is called
I have a constructor question for C#. I have this class: public partial class
I have a class whose constructor takes a const reference to a string. This
I have constructed a map and try to put subclasses of a given class
I have a base class called LabFileBase. I have constructed a List and have
I have a database class which is constructed so that it opens a connection
We have a small wrapper class that uses ResourceManager to load string resources from
I have a JavaScript class representing a car, which is constructed using two parameters,
I am fairly new to Java. I have constructed a single JUnit test class

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.