2013-01-01 52 views
0

喜的朋友在编译下面的错误来了错误:“的.class'预计

错误:”的.class'预计

我不是能找到什么错误。我查了很多网站,但无法找到为什么会出现这个错误。 Plz帮助

在此先感谢。

import java.io.*; 

class Test 
{ 
    boolean isGoodEmployee(boolean ismarried,int noofchild,String middlename,String childnames[]) 
    { 
     boolean child,letter,last,child; 

     if (noofchild <= 2) 
      child=true; 
     boolean firstletter = middlename.startsWith("k"); 
     boolean lastletter = middlename.endssWith("e"); 

     if (firstletter && (!lastletter)) 
      letter = true; 

     int lastnameletterscount = lastname.length(); 

     if (lastnameletterscount > 4) 
      last = true; 

     String name = raju; 

     for (int i=0; i < noofchild; i++) 
      if(name.equalsIgnoreCase(childnames[i])) 
      { 
       child = true; 
       break; 
      } 
    } 
} 


class GoodEmployee 
{ 
    public static void main(String args[]) throws IOException 
    { 
     String firstname, middlename, lastname; 
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
     System.out.println("enter the first name of employee"); 
     firstname = br.readLine(); 
     System.out.println("enter the middle name of employee"); 
     middlename = br.readLine(); 
     System.out.println("enter the last name of employee"); 
     lastname = br.readLine(); 
     //System.out.println("full name of employee is:"+first+middle+last); 
     System.out.println("enter employee is married or not"); 
     boolean ismarried = Boolean.parseBoolean(br.readLine()); 

     if (ismarried) 
      System.out.println("enter number of childrens"); 

     int noofchild = Integer.parseInt(br.readLine()); 
     String childnames[] = new String[noofchild]; 
     System.out.println("enter children names"); 

     for (int i=0; i < noofchild; i++) 
      childnames[i] = br.readLine(); 
     Test t = new Test(); 
     t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]); 
    } 
} 

我使用“的javac GoodEmployee.java”编译程序

+2

请缩进你的代码,这是非常难以阅读! –

+0

请输出完整错误 – fge

+1

请在您的问题中包含您用于编译文件的确切命令。你不是用'java'代替'javac'来编译,对吧? – thkala

回答

1

有很多不对的代码:
您在isGoodEmployee()(1号线)
声明布尔孩子的两倍 endssWith应该是endsWith()
等等,但它们不是你说的问题。你用什么命令行编译这个类?

4

您在isGoodEmployee中调用了不匹配的方法。

childnames参数被定义为一个阵列,这样就可以简单地在参数中传递,替换:

t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]); 

t.isGoodEmployee(ismarried,noofchild,middlename,childnames); 

除了,不要忽略其他的编译器的错误,例如as

middlename.endssWith("e"); 
       ^---------extra 's' 

熟悉javadocs

0

@Reimeus钉了它。

奇怪的编译错误可以解释如下。在这条线:

t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]); 

childnames[]短语应该是一个Java表达式。但事实上,这个语法最类似于一个类型......实际上是一个名为childnames的类(不存在)的一个数组。 Java编译器的语法错误恢复代码已经决定,如果它在类型名称(即childnames[].class)之后插入.class,它将提供语法上有效的表达式。

当然,编译器提出的修正是无意义的......至少因为在您的应用程序中不会有名为childnames的类或接口。


这个故事的寓意是不寻常的语法错误,有时会导致一个编译器产生奇特的错误信息,只有明智的,如果你能弄清楚如何解析器会解析错误输入。

0

如果您使用IDE,请使用公共主方法公开该类。 如果您试图使用命令窗口运行它,我认为编译时不需要“.class”文件,而是需要执行。因此,在通过输入javac GoodEmployee获得.class文件并且没有错误之后,请输入Java GoodEmployee,它将执行您拥有的.class文件。