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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:15:57+00:00 2026-05-25T10:15:57+00:00

I know a similar problem may have been presented here before, but i cannot

  • 0

I know a similar problem may have been presented here before, but i cannot find the answer on my own. To preface this, I have already found a workaround but would like to know why calling a constructor is failing. I will show the failed code and then working.

This code is a simple file analyzer, it reports the first last and ~middle (not exact) entries in a txt file. One of the requirements is recieving an argument from commandline.

Thanks for your time.

FAILED:

$ javac DataAnalyzerTester.java    
DataAnalyzerTester.java:11: cannot find symbol   
symbol  : constructor DataAnalyzer(java.lang.String)   
location: class DataAnalyzer   
analyze  = new DataAnalyzer(args[0]);    
-----------^


//DataAnalyzerTester.java

import java.util.*;
import java.io.*;

public class DataAnalyzerTester
{
    public static void main(String[] args)
    {
            DataAnalyzer analyze;
            analyze  = new DataAnalyzer(args[0]);
            //analyze.setFile(args[0]);
            System.out.println(analyze.min());
            System.out.println(analyze.max());
            System.out.println(analyze.avg());
    }
}


//DataAnalyzer.java
import java.util.*;
import java.io.*;

public class DataAnalyzer
{   
    public void DataAnalyzer(String fileN)
    {
        try
        {
            reader = new FileReader(fileN);
            Scanner in = new Scanner(reader);
            while(in.hasNextLine())
            {
                fileContent.add(in.nextLine());
            }
        }
        catch(IOException exception)
        {
            System.out.println("File not found. Try again Dumbass.");
        }
    }

    public void setFile(String fileN)
    {
        try
        {
            reader = new FileReader(fileN);
            Scanner in = new Scanner(reader);
            while(in.hasNextLine())
            {
                fileContent.add(in.nextLine());
            }
        }
        catch(IOException exception)
        {
            System.out.println("File not found. Try again Dumbass.");
        }
    }

    public  String min()
    {
        return fileContent.get(0);
    }

    public String max()
    {
        return fileContent.get(fileContent.size() - 1);
    }

    public String avg()
    {
        return fileContent.get((int) fileContent.size() / 2);
    }

    private FileReader reader;
    private ArrayList<String> fileContent = new ArrayList<String>();
}

Basically the above version does not work, but I added a setFile method to do the same thing as the constructor. My question then is why can i not call the constructor in this way? Thanks again.

  • 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-05-25T10:15:58+00:00Added an answer on May 25, 2026 at 10:15 am

    A constructor should not specify a return type – this combined with a name matching the class is how the compiler recognizes it as a constructor. So instead of:

    public void DataAnalyzer(String fileN)
    

    write:

    public DataAnalyzer(String fileN)
    

    More information: http://download.oracle.com/javase/tutorial/java/javaOO/constructors.html

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

Sidebar

Related Questions

Ok, I know similar questions have been asked, but my groveling through Google searches
I know this question is similar to several previous ones, but I can't find
I know there is a very similar question here but I was hoping to
Solution to original problem (below) may have been discovered. I commented out <identity> ...
I've been trying to find the answer to this question here. Several people seem
I have two computers. Both running WinXP SP2 (I don't really know ho similar
I know this is similar to this question , but I'm using SQL Server
I know this is very similar to a few other questions, but I can't
I know I have already answered a similar question ( Running Batch File in
The Disclaimer First of all, I know this question (or close variations) have been

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.