Подтвердить что ты не робот

Ошибка Eclipse: "Редактор не содержит основного типа"

Я не могу запустить следующий код в Eclipse. У меня есть основной метод, и это текущий файл. Я даже попробовал параметр "Запустить как", но я продолжаю получать эту ошибку: "редактор не содержит основного типа". Что я здесь делаю неправильно?

 public class cfiltering {

    /**
     * @param args
     */

    //remember this is just a reference
    //this is a 2d matrix i.e. user*movie
    private static int user_movie_matrix[][];

    //remember this is just a reference
    //this is a 2d matrix i.e. user*user and contains
    //the similarity score for every pair of users.
    private float user_user_matrix[][]; 


    public cfiltering()
    {
        //this is default constructor, which just creates the following:
        //ofcourse you need to overload the constructor so that it takes in the dimensions

        //this is 2d matrix of size 1*1
        user_movie_matrix=new int[1][1];
        //this is 2d matrix of size 1*1
        user_user_matrix=new float[1][1];
    }

    public cfiltering(int height, int width)
    {
        user_movie_matrix=new int[height][width];
        user_user_matrix=new float[height][height];
    }


    public static void main(String[] args) {
        //1.0 this is where you open/read file
        //2.0 read dimensions of number of users and number of movies
        //3.0 create a 2d matrix i.e. user_movie_matrix with the above dimensions. 
        //4.0 you are welcome to overload constructors i.e. create new ones. 
        //5.0 create a function called calculate_similarity_score 
        //you are free to define the signature of the function
        //The above function calculates similarity score for every pair of users
        //6.0 create a new function that prints out the contents of user_user_matrix 

        try
        {
            //fileinputstream just reads in raw bytes. 
            FileInputStream fstream = new FileInputStream("inputfile.txt");

            //because fstream is just bytes, and what we really need is characters, we need
            //to convert the bytes into characters. This is done by InputStreamReader. 
            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            int numberOfUsers=Integer.parseInt(br.readLine());
            int numberOfMovies=Integer.parseInt(br.readLine());

            //Now you have numberOfUsers and numberOfMovies to create your first object. 
            //this object will initialize the user_movie_matrix and user_user_matrix.

            new cfiltering(numberOfUsers, numberOfMovies);

            //this is a blankline being read
            br.readLine();
            String row;
            int userNo = 0;
            while ((row = br.readLine()) != null)   
            {
                //now lets read the matrix from the file
                String allRatings[]=row.split(" ");
                int movieNo = 0;
                for (String singleRating:allRatings)
                {
                    int rating=Integer.parseInt(singleRating);
                    //now you can start populating your user_movie_matrix
                    System.out.println(rating);
                    user_movie_matrix[userNo][movieNo]=rating;
                    ++ movieNo;
                }
                ++ userNo;
            }
        }
        catch(Exception e)
        {
            System.out.print(e.getMessage());
        }
    }

}
4b9b3361

Ответ 1

Попробуйте закрыть и снова открыть файл, затем нажмите Ctrl+F11.

Убедитесь, что имя исполняемого файла совпадает с именем проекта, в котором вы работаете, и что имя открытого класса в этом файле совпадает с именем проекта, над которым вы работаете в том числе.

В противном случае перезапустите Eclipse. Дайте мне знать, если это решит проблему! В противном случае, комментарий, и я попробую и помогу.

Ответ 2

Вы импортировали пакеты для чтения файлов.

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

также здесь

cfiltering(numberOfUsers, numberOfMovies);

Вы пытаетесь создать объект или вызвать метод?

тоже другое:

user_movie_matrix[userNo][movieNo]=rating;

вы присваиваете значение члену экземпляра, как если бы это была статическая переменная также удалите Th в

private int user_movie_matrix[][];Th

Надеюсь, что это поможет.

Ответ 3

private int user_movie_matrix[][];Th. должен быть `private int user_movie_matrix[][];.

private int user_movie_matrix[][]; должен быть private static int user_movie_matrix[][];

cfiltering(numberOfUsers, numberOfMovies); должен быть new cfiltering(numberOfUsers, numberOfMovies);

Независимо от того, работает ли код по назначению после этих изменений, выходит за рамки этого ответа; было несколько ошибок синтаксиса/неопределенности.