在1类相同的I类使一个实例:两个构造函数在具有不同参数
db = new AdapterDB (cal, rcarbohydrate, rfat, rprotein, getApplicationContext());
在2 I类作出instace:
db = new AdapterDB (Bits, Truncation, Crossover, Mutation, Chromosomes, Generation, getApplicationContext());
在类AdapterDB我使构造:
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public AdapterDB(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper (context);
}
double Truncation;
double Crossover;
double Mutation;
int Generation;
private Context context;
int indexOfChromosomes ;
int indexOfGens;
int gensNumber;
int chromosomesNumber;
String [][] population;
double [] fitnesstotal;
public AdapterDB(int Bits, double Truncation, double Crossover, double Mutation, int Chromosomes, int Generation, Context ctx)
{
this.indexOfGens = Bits;
this.Truncation = Truncation;
this.Crossover = Crossover;
this.Mutation = Mutation;
this.indexOfChromosomes = Chromosomes;
this.Generation = Generation;
this.context = ctx;
DBHelper = new DatabaseHelper (context);
population = new String[indexOfChromosomes][indexOfGens];
fitnesstotal = new double [indexOfChromosomes];
}
double cal;
double rcarbohydrate;
double rfat;
double rprotein;
public AdapterDB(double cal, double rcarbohydrate, double rfat, double rprotein, Context ctx)
{
this.cal = cal;
this.rcarbohydrate = rcarbohydrate;
this.rfat = rfat;
this.rprotein = rprotein;
this.context = ctx;
DBHelper = new DatabaseHelper (context);
}
在构造函数的值仍然存在,每个变量都有一个值,但是当我想在一些在类AdapterDB,cal,rcarbohydrate,rfat和rprotein的函数为零(0.0)为什么会发生这种情况?以及如何解决它?谢谢。
你确定它是一样的吗? –
是的,它仅在参数 – Michelle
上有所不同您能描述导致问题的事件序列吗?涉及哪些类,如何创建实例,何时何地传递等等? –