So these 2 files I am going to post are each in my DataBase package. The DBBinding class just needs to create an object with a string for the key and one for the value. Then the DBrecord is going to keep a collection of DBBindings that all have the same key string but diffrent value strings. For some reason I can not think/find the correct way to make a add method in DBrecord so that it calls the DBBinding class/objects constructor.
This is the method that is supposed to add the binding:
private void addRecord(String key_, String value_)
{
//DBBinding myDBBinding=new DBBinding(key_, value_);//constructor not defined error
//DBBinding myDBBinding(key_,value_);
//DataBase.DBBinding myDBBinding=new DataBase.DBBinding(key_, value_);//constructor not defined error
}
Here’s the DBBinding code followed by the DBrecord code.
package DataBase;
public class DBBinding {
private String key;
private String value;
public void DBBinding(String key_, String value_)
{
String key =new String(key_);
String value=new String(value_);
}
//public String toString()
//{return key+": "+value;}
}
and
package DataBase;
//package DataBase.*;
import DataBase.*;//did not help ... ?
public class DBrecord {
boolean select;
String key;
//need some type of collection to keep bindings.
public void DBrecord()
{
DBrecord myRecord=new DBrecord();
select=false;
}
private void addRecord(String key_, String value_)
{
//DBBinding myDBBinding=new DBBinding(key_, value_);//constructor not defined error
//DBBinding myDBBinding(key_,value_);
//DataBase.DBBinding myDBBinding=new DataBase.DBBinding(key_, value_);//constructor not defined error
}
public String toString()
{
//out put key first then all values in collection/group/record. use correct formatting.
}
}
In class
DBBindingyou must havepublic DBBinding(String key_, String value_), thevoidmakes the “constructor” actually to a method 🙂You have the same error in
DBrecord.By the way, don’t do this:
Strings are immutable, nothing can happen if you “share” them. But your code forces Java to create a new object for an absolutely identical value. So use just
However, in your case even this is wrong, as you create a new local variable
key“shadowing” the class variablekey. Look here for an explanation.So alltogether
DBBindingshould look like: