【问题标题】:Java, trying to compile, get following error message, what does this mean?Java,试图编译,得到以下错误消息,这是什么意思?
【发布时间】:2014-12-10 20:14:04
【问题描述】:

好的,所以当我尝试在 java 中编译它时,我收到以下错误消息

错误:仅当显式请求注释处理时才接受类名称“TokenTest” 1 个错误

这是什么意思,我该如何解决?我已经尝试了很多东西,但无法理解它指的是什么。谢谢你的帮助!这是否意味着我需要更改名称使其不是 TokenTest?

 import java.io.*;

  import java.util.*;

  class TokenTest {

     public static void main (String[] args) {
        TokenTest tt = new TokenTest();
        tt.dbTest();
     }
     void dbTest() {

        DataInputStream dis = null;
        String dbRecord = null;

        try {

           File f = new File("sales.info");
           FileInputStream fis = new FileInputStream(f);
           BufferedInputStream bis = new BufferedInputStream(fis);
           dis = new DataInputStream(bis);

           // read the first record of the database
           while ( (dbRecord = dis.readLine()) != null) {

              StringTokenizer st = new StringTokenizer(dbRecord, ",");
              String fname = st.nextToken();
              String lname = st.nextToken();
              String city  = st.nextToken();
              String state = st.nextToken();

              System.out.println("First Name:  " + fname);
              System.out.println("Last Name:   " + lname);
              System.out.println("City:        " + city);
              System.out.println("State:       " + state + "\n");
           }
        } catch (IOException e) {
           // catch io errors from FileInputStream or readLine()
           System.out.println("Uh oh, got an IOException error!" + e.getMessage());

        } finally {
           // if the file opened okay, make sure we close it
           if (dis != null) {
              try {
                 dis.close();
              } catch (IOException ioe) {
              }
           }//  end if
        }// end finally
     } // end dbTest
  } // end class

【问题讨论】:

    标签: java linux


    【解决方案1】:

    来自link about common problems when compiling Java

    Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

    如果您收到此错误,您在编译程序时忘记包含.java 后缀。请记住,命令是javac HelloWorldApp.java 而不是javac HelloWorldApp

    修复错误后,您会在以下行中收到有关使用已弃用方法的警告:

    while ((dbRecord = dis.readLine()) != null) {
    

    这是因为 DataInputStream#readLine 已被弃用。请参阅 the class Javadoc page 了解它被弃用的原因以及改用哪个 API。

    【讨论】:

    • 注意:TokenTest.java 使用或覆盖了已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。
    • 当我这样做时,我收到以下消息
    • 值得指出的是,如果你把错误文本和谷歌作为它,这个页面是第一个结果......
    • @Michael 给你一个新问题,你用 -Xlint:deprecation 重新编译了吗?
    • 不,我没有,直到现在才知道。像这样? javac -Xlint TokenTest.java
    【解决方案2】:

    如果您收到此错误,您在编译程序时忘记包含 .java 后缀。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多