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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:01:47+00:00 2026-05-13T11:01:47+00:00

The problem is: i have this code: public class Component { public Component() {

  • 0

The problem is: i have this code:

public class Component {
public Component() {
// TODO Auto-generated constructor stub
 }
 public double[] Shifts ;
 public double[][] Couplings ;

}

public class Decouplage {
 public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
  AllComponents = new Component(); 
  AllComponents.Shifts = GetShifts(...blah-blah-bla...);
  AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
 }

public Component AllComponents ; 
}

It works.
But when I try to create an array AllComponents[10] of this class Component

 public class Decouplage {
 public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
  AllComponents = new Component()[nComponents]; /////HOW MUST I PUT IN ONE LINE THE NUMBER OF ELEMENTS AND THE () FOR CONSTRUCTOR????
  for (int iCounter=0;iCounter<nComponents;iCounter++){
         AllComponents.Shifts = GetShifts(...blah-blah-bla...);
         AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
  }
 }
public Component[] AllComponents ; 
}

it does not compile.

But if I ignore the constructor’s ()

public class Decouplage {
 public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
  AllComponents = new Component[nComponents]; /////IS IT LEGAL TO IGNORE CONSTRUCTOR, EVEN IF IT IS EMPTY????
  for (int iCounter=0;iCounter<nComponents;iCounter++){
         AllComponents.Shifts = GetShifts(...blah-blah-bla...);
         AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
  }
 }
public Component[] AllComponents ; 
}

it can not resolve Shifts and Couplings as a fields…

What could you advise?
Note: GetShifts() has nothing with a standard Java’s getShift(). It is my own, it works well, i checked.

Thanx!

  • 1 1 Answer
  • 1 View
  • 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-05-13T11:01:48+00:00Added an answer on May 13, 2026 at 11:01 am

    There are two separate concepts here: creating an array of references, and creating instances of your class. So this line:

    AllComponents = new Component[nComponents]
    

    will create an array of Component references. Initially, all the references will be null. If you want to fill it with references to new instances, you’ll have to follow that line with:

    for (int i = 0; i < nComponents; i++)
    {
        AllComponents[i] = new Component();
    }
    

    EDIT: To reply to the comment, AllComponents is an array – it doesn’t have a concept of Shifts or Couplings. If you need to set the shifts or couplings for the new component, you should use either:

    for (int i = 0; i < nComponents; i++)
    {
        AllComponents[i] = new Component();
        AllComponents[i].Shifts = // Code here
        AllComponents[i].Couplings = // Code here
    }
    

    or

    for (int i = 0; i < nComponents; i++)
    {
        Component component = new Component();
        component.Shifts = // Code here
        component.Couplings = // Code here
        AllComponents[i] = component;
    }
    

    or add parameters to the constructor for Component to take the shifts and couplings.

    I’m assuming you’re a newbie at Java, by the way, and only want help on this specific problem at the moment – when you’re ready to move on, it would be worth looking at Java coding conventions, and encapsulating your data more robustly. (Using public variables is generally a bad idea.)

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

Sidebar

Related Questions

I have a problem with this code: (The error is below the code) public
I have this code, but I have a problem. When I update but do
I have a problem with a memory leak. I have this code in a
I have this code and can't figure out what seems to be the problem:
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and
I have this simple code, using Joda-time. Works fine, but I have a problem.
Problem Hello all! I have this code which takes my jpg image loops through
I have a cross-language problem regarding md5 :). I have this code in Java:
I have created this Fiddle with this code: This is my problem I want

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.