Tôi không tìm thấy lỗi nào trong lớp này, nhưng Netbeans liên tục hiển thị biểu tượng màu đỏ trên lớp đó. Lớp học làjava.lang.VerifyError: (class: ea/Individual, phương thức: <init> chữ ký: (I) V) Constructor phải gọi super() hoặc this()
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ea;
/**
*
* @author riyad
*/
import java.util.Random;
import java.util.BitSet;
public class Individual
{
BitSet variable;
double x;
double fitness;
double sharedFitness;
final int SIZE;
Random generator = new Random();
public Individual(int SIZE)
{
this.variable = new BitSet(SIZE);
this.fitness = 0;
this.sharedFitness = 0;
this.SIZE = SIZE;
for(int i=0; i<SIZE; i++)
{
if(generator.nextBoolean())
{
variable.set(i);
}
else
{
variable.clear(i);
}
}
x = Double.parseDouble(variable.toString());
}
public Individual copy()
{
Individual ind = new Individual(SIZE);
this.variable = (BitSet) ind.variable.clone();
this.fitness = ind.fitness;
this.sharedFitness = ind.sharedFitness;
this.x = ind.x;
return ind;
}
public void evaluate()
{
fitness = x * Math.sin(Math.sqrt(x));
}
public boolean getBit(int i)
{
return variable.get(i);
}
public BitSet getBitSet()
{
return variable;
}
public void setBit(int i)
{
variable.set(i);
}
public void clearBit(int i)
{
variable.clear(i);
}
public double getFitness()
{
return fitness;
}
public double sharedFitness()
{
return sharedFitness;
}
public void setSharedFitness(double fitness)
{
this.sharedFitness = fitness;
}
public void setFitness(double fitness)
{
this.fitness = fitness;
}
}
Mã được biên dịch nhưng bị lỗi thời gian chạy.
Exception in thread "main" java.lang.VerifyError: (class: ea/Individual, method: <init> signature: (I)V) Constructor must call super() or this()
Trong một lớp học, nơi lớp cá nhân đang được sử dụng:
ArrayList<Individual> pop = new ArrayList<Individual>();
này nơi lớp cá nhân đang được intantiated:
Individual temp = new Individual(STRING_SIZE);
pop.add(temp);
EDIT
tôi thiên đường' t đã đổi tên tệp theo cách thủ công. Tất cả các mã được thực hiện trong Netbeans. Vấn đề duy nhất là khi tôi tạo cá thể của Cá nhân.
EDIT2
tôi đã sao chép dự án nơi khác, mọi thứ đều bình thường trở lại. có thể là lỗi của Netbeans hoặc JDK
http://stackoverflow.com/questions/100107/reasons-of-getting-a-java-lang-verifyerror – stacker
Mã hiện tại có vẻ chính xác , vấn đề có thể là việc sử dụng lớp Cá nhân. Làm thế nào để bạn tạo một thể hiện của nó? – WoLfulus
@stacker: không hiểu một chút. Tôi e newbie – user