Eclipse错误:“编辑器不包含主类型” [英] Eclipse error: "Editor does not contain a main type"

查看:3343
本文介绍了Eclipse错误:“编辑器不包含主类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在Eclipse中运行以下代码。我有一个主要的方法,这是当前打开的文件。我甚至尝试了运行方式选项,但我不断得到这个错误:编辑器不包含主类型。我在这里做错了什么?

  public class cfiltering {

/ **
* @param args
* /

//记住这只是一个引用
//这是一个2d矩阵,即用户*电影
private static int user_movie_matrix [ ] [];

//记住这只是一个参考
//这是一个2d矩阵,即user *用户,并且包含
//每对用户的相似性得分。
private float user_user_matrix [] [];


public cfiltering()
{
//这是默认构造函数,它只是创建以下内容:
// ofcourse你需要重载构造函数使它占据维度

//这是大小为1的二维矩阵* 1
user_movie_matrix = new int [1] [1];
//这是大小为1的2d矩阵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这是你打开/读取文件的地方
//2.0读取用户数量和电影数量的尺寸
//3.0创建具有上述尺寸的2d矩阵ie user_movie_matrix。
// //你欢迎重载构造函数,即创建新的。
//5.0创建一个名为calculate_similarity_score的函数
//您可以自由定义函数的签名
//上述函数计算每对用户的相似度分数
/ /6.0创建一个打印出user_user_matrix的内容的新功能

try
{
// fileinputstream只读原始字节。
FileInputStream fstream = new FileInputStream(inputfile.txt);

//因为fstream只是字节,我们真正需要的是字符,我们需要
//将字节转换为字符。这是由InputStreamReader完成的。
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
int numberOfUsers = Integer.parseInt(br.readLine());
int numberOfMovies = Integer.parseInt(br.readLine());

//现在你有numberOfUsers和numberOfMovies来创建你的第一个对象。
//该对象将初始化user_movie_matrix和user_user_matrix。

new cfiltering(numberOfUsers,numberOfMovies);

//这是一个空白被读取
br.readLine();
字符串行;
int userNo = 0;
while((row = br.readLine())!= null)
{
//现在可以从文件中读取矩阵
String allRatings [] = row.split ();
int movieNo = 0;
for(String singleRating:allRatings)
{
int rating = Integer.parseInt(singleRating);
//现在你可以开始填充你的user_movie_matrix
System.out.println(rating);
user_movie_matrix [userNo] [movieNo] = rating;
++ movieNo;
}
++ userNo;
}
}
catch(异常e)
{
System.out.print(e.getMessage());
}
}

}


解决方案

尝试关闭并重新打开该文件,然后按 Ctrl + F11



验证您正在运行的文件的名称与您正在工作的项目的名称相同,并且该文件中的公共类的名称与您正在使用的项目的名称相同。



否则,重新启动Eclipse。让我知道这是否解决了这个问题!否则,评论,我会尝试和帮助。


I can't seem to run the following code in Eclipse. I do have a main method and this is the currently opened file. I even tried the "Run As" option but I keep getting this error: "editor does not contain a main type". What am I doing wrong here?

 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());
        }
    }

}

解决方案

Try closing and reopening the file, then press Ctrl+F11.

Verify that the name of the file you are running is the same as the name of the project you are working in, and that the name of the public class in that file is the same as the name of the project you are working in as well.

Otherwise, restart Eclipse. Let me know if this solves the problem! Otherwise, comment, and I'll try and help.

这篇关于Eclipse错误:“编辑器不包含主类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆