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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:51:50+00:00 2026-06-05T17:51:50+00:00

So after completing the last assignment I was given, I was instructed to take

  • 0

So after completing the last assignment I was given, I was instructed to take that code and change it from command line arguments to reading in data from a file. That all works out well, except for the part where I’m supposed to have an interface for a function that calls in the data from the file, then does the same things as before.

Right now, the object array in my driver class is SUPPOSED to be assigned the values taken in by the DAO class. The DAO class is based off the interface. The driver class is screaming at me that the object I have created has to be assigned from a static function in the DAO class, but that method can’t be static…

What did I miss this time?..

Interface:

public interface ScanTextFile {

    public Object[] readTextData() throws FileNotFoundException;
}

DAO Class:

public class StudentDAO implements ScanTextFile {

    public Object[] readTextData() throws FileNotFoundException {

        Student[] studentRecord = new Student[3];

        String dataFileName = "data.txt";
        int numberOfRows = 0;

        File dataFile = new File(dataFileName);
        Scanner scan = new Scanner(dataFile);
        int i = 0;
        String delim = "\\|";

        // checks number of rows in data file, making sure there are 3 total
        for(i = 0; scan.hasNextLine(); i++){
            numberOfRows++;
        }
        if(numberOfRows < 3){
            System.err.format((numberOfRows) + " argument(s) - expected 3");
            System.exit(0);
        } else if(numberOfRows > 3){
            System.err.format((numberOfRows) + " arguments - expected 3");
            System.exit(0);
        }

        for(i = 0; i < numberOfRows; i++){
            if(scan.hasNextLine()){
                String temp = scan.nextLine();
                String[] tempData = new String[4];
                Student tempStudent = null;

                for(i = 0; i < tempData.length ; i++){
                    tempData = temp.split(delim);
                }
                System.out.println("DEBUG *** Finished extracting data, creating object...");
                System.out.println("DEBUG Student Data = [�" + temp + "]");

                GregorianCalendar date = new GregorianCalendar();
                try {
                    date = DateUtil.convertFromDMY(tempData[3]);
                } catch (ParseException e1) {
                    e1.printStackTrace();
                }

                tempStudent = new Student(tempData[0], tempData[1], tempData[2], date);
                studentRecord[i] = tempStudent;
            }
        }

        return studentRecord;
    }

}

Driver Class:

public class Lab3 { 

    public void main(String[] args) throws ParseException, FileNotFoundException{

        Student[] allData = new Student[3];
        allData = (Student[]) StudentDAO.readTextData();

        System.out.println("");
        System.out.println("DEBUG *** Student Objects created, displaying all Students...\n");
        for(Student s : allData){
            Print.print(s);
        }
    }
}

edit
Thanks for pointing out that error, thanks everyone, but now I’m getting

Exception in thread “main” java.lang.NoSuchMethodError: main

Is that because StudentDAO has no main?

another edit

@mprabhat thanks for pointing out a really stupid error, still don’t know how I didn’t see that ><

Now I have an issue when the scanner attempts to read the data in from the file.

1 – says data file can’t be found, even though it’s in my src folder.

2 – error on the scanner line as well, should I not be using a scanner on a file? should I be going with … DataInputStream?

  • 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-05T17:51:52+00:00Added an answer on June 5, 2026 at 5:51 pm

    Your method readTextData is not static but you are accessing it like a static method by using class name StudentDAO

    StudentDAO.readTextData();
    

    Instead create an object StudentDAO and then call readTextData

    Student[] allData = new Student[3];
    StudentDAO studentDAO  = new StudentDAO();
    allData = (Student[]) studentDAO.readTextData();
    

    Issue in your Lab3 is that you dont have correct signature of your main method.

    public static void main(String[] args) is the correct signature, your signature is missing static, hence you are getting java.lang.NoSuchMethodError: main

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

Sidebar

Related Questions

After completing an assignment to create Pascal's triangle using an iterative function, I have
After using Instruments, I have found the a spot in my code that is
After completing the tutorial from the codeigniter user guide I ran into a problem
Do the international students get a job offer in Australia after completing their Masters degree from University of Melbourne?
I have recently started working on a very large C++ project that, after completing
After completing the following code the value of result1 and result2 variables (measured width
How do I destroy instance variable after completing one ajax call. In my app
Hi I have a Sticky form that after successful completion I want to clear
After updating from ruby-1.8.7-p352 to ruby-1.8.7-p358 via rvm , gems are still installed to
After constructing the bean, I want to retrieve data from the database, using the

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.