2016-07-03 10 views
-4

私はjarファイルを持っている必要があるプロジェクトを持っていますが、開かないでください、誰でも私を助けてくれますか、私は大学にできるだけ早く必要です。私はプロジェクトのjarファイルを開くことができません

package huffmanproject; 

import java.util.ArrayList; 
import java.util.PriorityQueue; 

public class huffmanproject { 

    public static class HuffNode implements Comparable<HuffNode> { 

     public int value; 
     public int weight; 
     public HuffNode leftTree; 
     public HuffNode rightTree; 
     public HuffNode parent; 

     public HuffNode() { 
      parent = null; 
     } 

     public HuffNode(int v, int w, HuffNode lTree, HuffNode rTree, HuffNode par) { 
      value = v; 
      weight = w; 
      leftTree = lTree; 
      rightTree = rTree; 
      parent = par; 
     } 

     @Override 
     public int compareTo(HuffNode rhs) { 
      return weight - rhs.weight; 
     } 

     @Override 
     public String toString() { 
      String str = ""; 
      str += this.value; 
      return str; 
     } 
    } 

    public static class HuffTree { 

     private int size = 0; 
     private HuffNode root = new HuffNode(); 
     private PriorityQueue<HuffNode> huffQueue = new PriorityQueue(); 
     public ArrayList<String> pathTable = new ArrayList(); 
     public ArrayList<Character> valueTable = new ArrayList(); 

     public HuffTree(int[] freq, char[] code) { 

      this.size = freq.length; 

      if (freq.length != code.length) { 
      throw new UnsupportedOperationException("Error: Character and code length mismatch."); 
      } 

      for (int i = 0; i < this.size; i++) { 
       huffQueue.offer(new HuffNode(code[i], freq[i], null, null, null)); 
      } 
      createTree(); 
      createTable(this.root, ""); 
     } 

     private void createTree() { 
      while (huffQueue.size() > 1) { 
       HuffNode tempL = huffQueue.poll(); 
       HuffNode tempR = huffQueue.poll(); 
       HuffNode parent = new HuffNode(0, tempL.weight+tempR.weight, tempL, tempR, null); 
       tempL.parent = parent; 
       tempR.parent = parent; 
       huffQueue.offer(parent); 
       this.size++; 
      } 
      this.root = huffQueue.peek(); 
     } 
     private void createTable(HuffNode curr, String str) { 
      if (curr == null) return; 
      if (curr.leftTree == null && curr.rightTree == null) { 
       char tempChar; 
       if (curr.value == 32) 
        tempChar = ' '; 

       if (curr.value == 10) 
        tempChar = 'n'; 

       else 
        tempChar = (char)curr.value; 
       this.valueTable.add(tempChar); 
       this.pathTable.add(str); 
      } 
      str += "0"; 
      createTable(curr.leftTree, str); 
      str = str.substring(0, str.length()-1); 
      str += "1"; 
      createTable(curr.rightTree, str); 
     } 
     String tacks = ""; 
     public void getTree(HuffNode curr) { 
      if (curr == null) return; 
      if (curr.leftTree == null && curr.rightTree == null) { 
       switch (curr.value) { 
        case 32: 
         System.out.println(tacks + curr.weight + ": sp"); 
         break; 
        case 10: 
         System.out.println(tacks + curr.weight + ": nl"); 
         break; 
        default: 
         System.out.println(tacks + curr.weight + ": " + (char)curr.value); 
         break; 
       }    
      } 
      else 
       System.out.println(tacks + curr.weight); 
      tacks += "- "; 
      getTree(curr.leftTree); 
      getTree(curr.rightTree); 
      tacks = tacks.substring(0, tacks.length()-2); 
     } 
     public int getSize() { return this.size; } 
     public String encode(String input){ 
      String str = ""; 
      for (int x = 0; x < input.length(); x++) { 
       for (int i = 0; i < valueTable.size(); i++) { 
        if (valueTable.get(i) == input.charAt(x)) 
         str += pathTable.get(i); 
       } 
      } 
      return str; 
     } 
     public String decode(String bits) { 
      String decodedStr = ""; 
      for (int i = 0; i < bits.length(); i++) { 
       if (!getChar(bits.substring(0, i+1)).equals("")) { 
        decodedStr += getChar(bits.substring(0, i+1)); 
        bits = bits.substring(i+1); 
        i = 0; 
       } 
      } 
      return decodedStr; 
     } 
     private String getChar(String bits) { 
      String character = ""; 
       for (int i = 0; i < pathTable.size(); i++) { 
        if (pathTable.get(i).equals(bits)) 
         character = valueTable.get(i).toString(); 
       } 
      return character; 
     } 
    } 
     public static void main(String[] args) { 
      // for example assume that we have these letters with these different frequencies like below: 
      int freq[] = {10, 15, 12, 3, 4, 13, 1}; 
      char code[] = {'a', 'e', 'i', 's', 't', ' ', '\n'}; 
      HuffTree hTree = new HuffTree(freq, code); 
      System.out.println("Display Tree:"); 
      HuffNode curr = hTree.root; 
      hTree.getTree(curr); 
      System.out.println(""); 
      // and we want to build the huffman tree of the word sea : 
      System.out.println("Encode 'sea': " + hTree.encode("sea") +"\n"); 
      System.out.println("Decode '" + hTree.encode("sea") + "': " +           hTree.decode(hTree.encode("tea"))); 
     } 
} 
+0

どのようにしようとしていますそれを開く?実行可能なJARとしてエクスポートされましたか? – CConard96

+0

java(TM)platform SEバイナリ – tina

+0

すぐに開くのではなく、すぐに終了しないのですか?プログラムにはインターフェースがなく、ユーザーの入力を求めません。したがって、コマンドプロンプトウィンドウですべてを実行してから閉じることができます。 JARの場所からコマンドプロンプトウィンドウで "java -jar JAR_FILE.jar"を実行してみてください。 – CConard96

答えて

0

単純にjarファイルにコンパイルしていない場合は、コマンドプロンプトまたはターミナルで次のコマンドを試してみてください。オラクルから

jar cf jar-file input-file(s) 

Creating jar File

コマンドプロンプトを開くには、入力して実行]ボックスにcmdと押しを開くにはWIN + Rを使用しています。

あなたのjavaファイルのディレクトリに移動します。

cd C:\Path\to\my\java\file\HuffNode.java 

は、コマンドを実行します。

jar cf HuffNode.jar HuffNode.java 

あなたが複数の.javaファイルがある場合:

jar cf HuffNode.jar File1.java File2.java File3.java 
+0

私はcmdの使い方がわかりません、もっと説明してください – tina

+0

私は自分の答えを編集します – mcjcloud

+0

また、CConard62のように、コマンドプロンプトからコンパイルしたjarをダブルクリックする代わりに実行してみてくださいそれは本当に速く開閉していないことを確認してください – mcjcloud

関連する問題