[英]TELEPHONY_SERVICE constant not recognised in one class, but is in another
[英]Object of one class not recognised while compiling in another
假設在使用Java的程序包中,我們使用2個文件。 第一個說StudentModel.java和第二個說StudentView.java。
studentModel.java的基本結構為:
package student;
public class StudentModel{
private String name;// name of student
private int roll; // roll of student
private String date;
private int marks[]=new int [6];
private String sub[]=new String[6];
private int total;
/*to get the details of a student*/
public int getRoll();
public String getDate();
public String getName();
public void setDate(String dat);
public void setName(String nam);
public void setRoll(int roll);
public void setSubjectAndMarks(int [] mar,String [] subject){
for(int i =0;i<6;i++) {
marks[i]=mar[i];
sub[i]=subject[i];
}
}
public void displaySubjectAndMarks(){
for(int y=0;y<5;y++) {
System.out.println(sub[y]+"\t \t\t "+marks[y]);
}
}
public int getTotal();
}
StudentView.java的基本結構是:
package student;
import java.util.*;
public class StudentView {
/*displaying the marksheet of a particular student*/
public void display(StudentModel Obj) {
System.out.println("-------------------MARKSHEET---------------");
System.out.println("\nName:"+Obj.getName()+"\tDate : "+Obj.getDate());
System.out.println("------------------------------------");
System.out.println("ROLL NO :\t\t" +Obj.getRoll());
System.out.println("-------------------------------");
System.out.println("SUBJECT \t\t MARKS");
Obj.displaySubjectAndMarks();
System.out.println("TOTAL"+Obj.getTotal());
}
}
然后,我首先編譯了StudentModel.java ,沒有給出任何錯誤。 然后我編譯了StudentView.java ,引發了這個錯誤:
StudentView.java:18: error: cannot find symbol
public void display(StudentModel Obj) {
symbol: class StudentModel
location: class StudentView
1 error
我正在從終端進行編譯,即使添加了類路徑之后,我仍然收到此錯誤:
我自己不經常使用Java命令行,但是能夠重現該問題。
對我而言,解決此問題的原因是一次傳遞所有源文件,例如:
javac StudentModel.java StudentView.java
可能有更好的解決方案,但是我希望這對您有所幫助。
提示:如果您有make
你可以用它來編譯,所以你不必鍵入了一切所有的時間。
一個更簡單的解決方案是僅使用IDE tbh。
編輯:
我很好奇,看了一下文檔( 鏈接 ),其中指出: “對於命名包中的.class文件,類路徑以包含“ root”包(完整包名稱中的第一個包)的目錄結尾。 ”
您的課程位於一個名為“ student
的程序包中,因此,編譯器將從類路徑根目錄中查找一個名為“ student”的文件夾,在該文件夾中可以在student
程序包中查找.class文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.