Error: Main method not found in class inter333, please define the main method as: public static void main(String[] args)

Trapper :

im trying to create a program that outputs the intersection of 2 sorted files of strings in O(n) time. This is what I have so far and im getting an error called "Error: Main method not found in class inter333, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application" So I put "public static void main(String[] args)" in and it returns 0 but it doesnt output the intersection of the two files...

import java.io.File;

import java.util.*;

import java.io.BufferedReader;

import java.io.FileReader;

public class inter333
{
    public static void main(String[] args) {}
    List<String> SampleStringA = new ArrayList<String>();
    List<String> SampleStringB = new ArrayList<String>();
    File SampleStringAFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1ma.txt");
    File SampleStringBFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1mb.txt");
    BufferedReader reader = null;

    public List<String> readFiles(){
        try {
            reader = new BufferedReader(new FileReader(SampleStringAFile));
            String text = null;
            while ((text = reader.readLine()) != null) {
                SampleStringA.add(text);
            }

        }
        catch (Exception e) {
            e.printStackTrace();
        }
        try
         {
            reader = new BufferedReader(new FileReader(SampleStringBFile));
            String text = null;
            while ((text = reader.readLine()) != null) {
                SampleStringB.add(text);
            }

        }
        catch (Exception e1) {
            e1.printStackTrace();
        }

        return this.intersection(SampleStringA, SampleStringB);
    }
    public <T> List<T>  intersection(List<T> list1, List<T> list2)
    {
        List<T> list = new ArrayList<T>();

        for (T t : list1) {
            if(list2.contains(t)){
                list.add(t);
            }

        }
        return list;

    }
}
C2H50H :

You need to actually call your readFiles() method from the main class to start it and also move your class variables to be under your class declaration.

public class inter333 {

    List<String> SampleStringA = new ArrayList<String>();
    List<String> SampleStringB = new ArrayList<String>();
    File SampleStringAFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1ma.txt");
    File SampleStringBFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1mb.txt");
    BufferedReader reader = null;

    public static void main(String[] args) {
        readFiles();
    }

    /*Other methods*/
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=400764&siteId=1