2016-06-11 12 views
0

私は丁寧な問題が既にここで解決されていることを知っていますが、まだすべての答えはまだ私の問題を解決できません。問題は、このです:クラスのコンストラクタを指定された型に適用することはできません - 抽象クラス

私はこのようなコンストラクタを含む、ノードである抽象クラスを持っている:

public Node(List<Record> dataSet, int labelIndex) { 
    this.allSamples = new ArrayList<Integer>(); 
    this.dataSet = dataSet; 
    this.classificationLabelIndex = labelIndex; 
    this.entropy = 0; 
} 

そして、私は(スーパー使用する)このようなコンストラクタを含む、ツリーノードにabsractクラスを拡張します:だから、

public TreeNode(List<Record> dataSet, int labelIndex, List<Attribute> attributes, int level, double threshhold) { 
    super(dataSet, labelIndex); 
    this.attributes = attributes; 
    splittedAttrs = new HashSet<Integer>(); 
    this.level = level; 
    this.displayPrefix = ""; 
    this.children = null; 
    this.threshhold = threshhold; 
} 

、のTreeNodeクラスは抽象Nodeクラスを拡張し、Nodeクラスからデータセットとlabelindexを呼び出すために、スーパーメソッドを使用して、その後私は、クラスノードにおけるコンストラクタノードが指定されたタイプに適用することはできません」の警告を取得、引数を必要としません"たぶん、TreeNodeにいくつかのパラメータを追加していたかもしれないが、私はまだそれが起こりそうにないと思う。どんな助けもありがたい。

+0

明確化(またはより良いコードを表示)してください。 – Argb32

+0

私は抽象クラスをインスタンス化できないので、Objectのデフォルトのインスタンスを使用するだけで、コンストラクタを無視することができると思います。ちょうどアイデア – RobotKarel314

+0

それはすでに人を働いた、私はちょうどNetbeansを再起動する必要があります... Thx –

答えて

2

詳細を確認することなく、問題の内容を知ることは難しいです。いいえ、抽象クラスを直接インスタンス化することはできませんが、抽象クラスのコンストラクタをサブクラスから呼び出すことができます。 1つのアイデアは、NodeまたはTreeNodeと呼ばれる別のクラスと競合するクラスパスの問題がないことを確認することです。実際に、あなたはこれらをインポートした場合、既に例えば、あなたのクラスパスに存在している場合がありますカスタムクラスを作成している: https://docs.oracle.com/javase/7/docs/api/javax/swing/tree/TreeNode.html https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Node.html

がMyTreeNodeとMYNODEまたは何のようなあなたのためのより具体的な何かにそれらの名前を変更してください。

あなたが送信したコードでできる限り最善の方法で複製を試みましたが、私の最後に問題は見られませんでした(つまり、クラスパス内の他のインポートとの衝突はありません)。これをチェックし、あなたの持っているものと一致するかどうかを確認してください。そうでない場合は、エラーのスタックトレースと、すべてのコードをコピー/貼り付けてください。おかげ

import java.util.ArrayList; 
import java.util.List; 

import java.util.ArrayList; 
import java.util.List; 

public abstract class Node { 

private List<Integer> allSamples; 
private List<Record> dataSet; 
private int classificationLabelIndex; 
private int entropy; 

public Node(List<Record> dataSet, int labelIndex) { 
    this.allSamples = new ArrayList<Integer>(); 
    this.dataSet = dataSet; 
    this.classificationLabelIndex = labelIndex; 
    this.entropy = 0; 
} 

}

import java.util.ArrayList; 
import java.util.HashSet; 
import java.util.List; 
import java.util.Set; 

public class TreeNode extends Node { 

private List<Attribute> attributes; 
private Set<Integer> splittedAttrs; 
private int level; 
private String displayPrefix; 
private Object children; 
private double threshhold; 

public TreeNode(List<Record> dataSet, int labelIndex, 
     List<Attribute> attributes, int level, double threshhold) { 
    super(dataSet, labelIndex); 
    this.attributes = attributes; 
    splittedAttrs = new HashSet<Integer>(); 
    this.level = level; 
    this.displayPrefix = ""; 
    this.children = null; 
    this.threshhold = threshhold; 
} 

public static void main(String[] args) { 
    Node node = new TreeNode(new ArrayList<Record>(), 1, 
      new ArrayList<Attribute>(), 1, 1.1); 

} 

}警告を取得するとき

class Record {} 
class Attribute {} 
関連する問題