无法找到方法java

时间:2015-11-10 22:45:31

标签: class methods public

所以我运行以下程序,我的cmd提示符给出了一个错误,指出在DataElements类中找不到getDescriptions()方法。我确定这是一个简单的解决方案,但我只是卡住了。这是DataElements类:

import java.io.*;

public class DataElements
{
File file;

private int columns;

private int row;

private int length;

private String name;

private String type;

private int position;

private String[] descriptions;


public File getFile(){
    return file;
}

public void setFile(File f){
    file = f;
}

public int getColumns(){
    return columns;
}

public void setColumns(int c){
    columns = c;
}

public int getRow(){
    return row;
}

public void setRow(int r){
    row = r;
}

public int getLength(){
    return length;
}

public void setLength(int l){
    length = l;
}

public String getName(){
    return name;
}

public void setName(String n){
    name = n;
}

public String getType(){
    return type;
}

public void setType(String t){
    type = t;
}

public int getPosition(){
    return position;
}

public void setPosition(int p){
    position = p;
}

public String[] getDescriptions(){
    return description;
}

public void setDescriptions(String[] d){
    description = d;
}
}

这是主要方法。如果您需要CMSReader类让我知道,但问题似乎停留在这两个类

import java.util.Scanner;
import java.io.*;

public class Project2{
public static void main(String[] args) throws FileNotFoundException{
    Scanner keyboard = new Scanner(System.in);
    boolean fileParsed = false;
    String inFile;
    String outFile;


    if(args.length != 1){
        System.out.println("Error. Enter one argument: the file that needs to be parsed.");
        System.exit(0);
    }

    Scanner scan = new Scanner(new File(args[0]));

    DataElements storage = new DataElements();

    CMSReader reader = new CMSReader(scan,storage);


    reader.scanTopData();

    System.out.println("Input File - " + storage.getName());
    System.out.println("Output File - ");//*************Look at this*********************
    System.out.println("Number of Variables - " + storage.getColumns());
    System.out.println("Number of Records - " + storage.getRow());
    System.out.println("Record Length - " + storage.getLength());
    System.out.println("Variable information:");

    reader.scanVariableData();

    String[] variableData = storage.getDescriptions();

    for(int i = 0; i < variableData.length ; i++){
        System.out.println(variableData[i]);
    }
}
}

我感谢任何帮助。就像我说的那样,我确定它有些愚蠢,但我已经看了太久了。

1 个答案:

答案 0 :(得分:0)

变量description未在DataElements类中声明,这就是DataElements文件无法编译的原因,我的猜测是你有一个较旧的编译版本(.class文件) DataElements不包含该方法。

<强>建议
开始使用一个好的IDE(IntelliJ是我个人最喜欢的,但Eclipse和Netbeans也是不错的选择)。一个好的IDE,除了它提供的所有其他好东西之外,还会以一种你不会错过的方式强调这些问题。