java - 错误无法在同一包中找到具有接口(interface)的符号

标签 java import package

你好,我的软件向导网络。我有一个问题,为什么我无法编译我的类(class)。我不断收到错误:找不到符号。所有这些类都在同一包 blocklaw 中。我已经尝试了导入语句的每种变体,但似乎无法消除此错误。目录结构是blocklaw --> src --> all_classes_here。 我也尝试更改包声明 blocklaw.src 但仍然没有帮助。 我将在这里分享我的代码,

 package blocklaw;

    import java.security.MessageDigest;
    /*
    * returns a string value of the true fact
    */
    public class TrueFact implements Hashable {
      private String trueFact;
      private String hashFact;
      private String source;
      private String hashSource;
      private int bytesLength;
      private String hashedBytesLength;
      private String hashedHash;

      public TrueFact(String trueFact, String source){
        this.trueFact = trueFact;
        this.source = new Source(source).getSource();
        byte[] bytes = trueFact.getBytes("UTF-8");
        this.bytesLength = bytes.length;
        setHashCode();
      }

      public String getTrueFact(){
         return this.trueFact;
      }

      public String getHashFact(){
        return this.hashFact;
      }

      public String getSource(){
        return this.source;
      }

      public int getbytesLength(){
        return this.bytesLength;
      }

      public String getHashedBytesLength(){
        return this.hashedBytesLength;
      }

      public void setHashCode(){
        this.hashFact = hash(this.trueFact);
        this.hashSource = hash(this.source);
        this.hashedBytesLength = hash(String.valueOf(this.bytesLength));
        this.hashedHash = hash(this.hashFact+this.hashSource+this.hashedBytesLength);
      }

      public String getHashSource(){
        return this.hashSource;
      }

      public String hash(String input){
        try {
           MessageDigest digest = MessageDigest.getInstance("SHA-256");

           //Applies sha256 to our input,
           byte[] hash = digest.digest(input.getBytes("UTF-8"));

           StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal
           for (int i = 0; i < hash.length; i++) {
              String hex = Integer.toHexString(0xff & hash[i]);
              if(hex.length() == 1) hexString.append('0');
              hexString.append(hex);
           }
           return hexString.toString();
        }
        catch(Exception e) {
           throw new RuntimeException(e);
        }
      }
     }

据我了解,同一包中的所有类不需要显式导入。那么为什么我的错误是找不到该符号呢?

以下是Hashable的接口(interface)...

package blocklaw;

public interface Hashable{
    public String hash();
}

最佳答案

正如所讨论的,这些是纠正答案所需遵循的步骤。

Compile Source.java
And the String input parameter to the hash function in Hashable.java
Compile Hashable.java
Now go one folder level up.
Add necessary try catch blocks in TrueFact.java
Build blocklaw/TrueFact.java

这将编译 TrueFact.java。

关于java - 错误无法在同一包中找到具有接口(interface)的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58066133/

相关文章:

java - th :disabled objects in Thymeleaf

java - Apache Camel - 无效数据格式的错误邮件处理

android - 如何将现有的android项目导入到另一个android项目中

c# - 使用线程通过 API 为数千用户导入数据

java - usb4java:无法进行数据传输

使用 JAR 的 Java 小程序?

node.js - 具有NodeJS/CommonJS样式模块系统的语言

python - 如何在 Python 中使用 Anaconda 删除模块

java - 默认 jar 文件和 tests.jar 的不同 MANIFEST.MF

ubuntu快速换包安装文件夹