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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:33:05+00:00 2026-06-13T20:33:05+00:00

I am trying to initialise the array C in the loop, but it gives

  • 0

I am trying to initialise the array C in the loop, but it gives error :
C is array of class ipdata and I have declared it and trying to initialise it inside the loop.

import java.io.*;
import java.util.*;
public class cluster_anlysis {
    class ipdata{


        float a,b;
        int cluster;

        ipdata()
        {
            a=0;
        }
    }
    public float modc(float a){
            if(a<0.0)
                a=-a;
            return a;
    }
    public static void main(String[] args) {
        cluster_anlysis obj=new cluster_anlysis();
    ipdata C[] = new ipdata[50];
    float mean1,mean2,mean3;
    int i,j,n1=0,n2=0,n3=0,flag=0;
    float ina=0.0f;
    float inb=0.0f;

    //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Scanner scan =new Scanner(System.in);
    System.out.println("pls enter no of data: ");
    Integer no = scan.nextInt();
    System.out.println("\nnow enter the x and y values");
    for(i=0;i<no;i++)
    {
        ina=scan.nextFloat();
        inb=scan.nextFloat();
        System.out.println(ina);
        C[i]= new ipdata();          // this line is giving error

        C[i].a=ina;
        C[i].b=inb;
        C[i].cluster=0;
    }


    }

}

What could be the problem ?
it says :
No enclosing instance of type cluster_anlysis is accessible. Must qualify the allocation with an enclosing instance of type cluster_anlysis (e.g. x.new A() where x is an instance of cluster_anlysis).

  • 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-13T20:33:06+00:00Added an answer on June 13, 2026 at 8:33 pm

    you create an instance of inner class from static methods of your outer class using the outer class instance.

    c[i]= new cluster_anlysis().new ipdata();
    

    as you have alread created cluster_anlysis instance in your first line of main method.

    cluster_anlysis obj = new Cluster_anlysis();
    

    you could simple do.

    c[i]= obj.new ipdata();
    

    read about Inner classes in java

    but if you want to create an inner class instance from the non-static methods of your outer class you dont need the instance of your Outer Class .

     public class OuterClass {
           public void method(){
               InnerClass inner = new InnerClass();
           }
           class InnerClass{
             }
        }
    

    and also follow class name convention as posted by @A.R.S and @JB Nizet in their solutions.

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

Sidebar

Related Questions

I am trying to get the following loop working to fill an array of
I'm trying to initialise a structure which ends with an array[0] (here, char iedata[0]
I have been trying to figure this out for several hours but have had
My title is a bit confusing, but I'm trying to write a loop that
I am trying to loop through an integer array using C# Iterators. The program
In the code below, I am trying to use a for loop to initialise
I'm trying to initialise an array of Photo s, and am doing so like
I'm trying to initialise a 2D array in Perl that is basically a schedule.
I am trying to initialise a generic class with all the availables values from
Stuck here trying to initialize an array (c#) using a loop. The number of

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.