简体   繁体   English

“无法解析为类型”

[英]“Cannot be resolved to a type”

Trying to create a new instance of an object. 尝试创建对象的新实例。 I want to create a new film and have it displayed in an arraylist. 我想创建一部新电影,并将其显示在arraylist中。

So I have two classes. 所以我有两节课。

Class 1 1类

public class Films {

//Film Attributes
private String title, studio, director;
private int release, duration, rating;


//default constructor
public Films(){
    title = null;
    studio = null;
    director = null;
    release = 0;
    duration = 0;
    rating = 0;
}

//Start of Film method
public void setFilms(String title, String studio, String director, 
                  int release, int duration, int rating) 
{
    this.title = title;
    this.studio = studio;
    this.director = director;
    this.release = release;
    this. duration = duration;
    this.rating = rating;
}//end of Film method

//Start of getString method
public String getString(){
    return "\nTitle: " + title + "\nRelease: " + release + "\nDuration: " + duration
            + "\nStudio: " + studio + "\nDirector: " + director + "\nRating: " + rating
            + "\n";
}//end of getString method

} }

and class 2 和2级

    //start of createFilm() method
private static void createFilm(){

    Films newfilm = new Films(); //create a new instance of a film object

    System.out.println("Film Title: ");
    String title = in.next();

    System.out.println("Release Date: ");
    int release = in.nextInt();

    System.out.println("Duration: ");
    int duration = in.nextInt();

    System.out.println("Studio: ");
    String studio = in.next();

    System.out.println("Director: ");
    String director = in.next();

    System.out.println("Rating: ");
    int rating = in.nextInt();

    newfilm.setFilms(title, release, duration, studio, director, rating);
    myfilms.add(newfilm);
}

} }

I only included the method which i am having trouble with in class 2. Basically the trouble im having is in class 2, the line; 我只在第2类中包括了我遇到麻烦的方法。基本上,在第2类中,我遇到的麻烦是线路。

Films newfilm = new Films(); //create a new instance of a film object

is telling me 'Films cannot be resolved to a type' x2. 告诉我“电影无法解析为类型” x2。 So both 'Films'. 所以都是“电影”。

I imagine its something very stupid and silly that i've overlooked, assumed or missed out but I cant figure out what the problem is. 我想象它被我忽略,假定或错过了,但它非常愚蠢和愚蠢,但是我无法弄清楚问题出在哪里。

This is my first post on this subject as you can probably tell so im sorry if i've missed out valuable and key information and parts of the code. 这是我关于该主题的第一篇文章,如果您错过了宝贵的关键信息和部分代码,您可能会非常抱歉。 I'm new to programming. 我是编程新手。

It is an import issue you need to add import statment here is an example 这是一个导入问题,您需要添加导入语句,这是一个示例

Notice first line package com.ura.stam.com.ura.stammm; 注意第一行程序包com.ura.stam.com.ura.stammm; it is basicly a place where your class is placed 基本上是您上课的地方

package com.ura.stam.com.ura.stammm;

public class MyFilms {

public MyFilms(){
    System.out.println("Callin constructor of films class");
}

} }

Now look how i import it to other class Notice the second line import com.ura.stam.com.ura.stammm.MyFilms; 现在看我如何将其导入其他类。注意第二行import com.ura.stam.com.ura.stammm.MyFilms; it tells the compile to bring this class to MyTestClass 它告诉编译器将此类带入MyTestClass

package com.ura.stam.com.ura.sdss;
import com.ura.stam.com.ura.stammm.MyFilms;

public class MyTestClass{
public static void main(String[] args) {
    MyFilms myFilms = new MyFilms();
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM