Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error compiling DataClientLocal

 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres the code: Interface
package suncertify.db;
import java.io.*;
import java.util.*;
import java.rmi.*;
public interface DataClient extends Remote
{
public FieldInfo [] getFieldInfo()throws RemoteException;
public DataInfo getRecord(int recNum)throws DatabaseException, RemoteException;
public DataInfo find(String toMatch)throws DatabaseException, RemoteException;
public void add(String [] newData)throws DatabaseException, RemoteException;
public void modify(DataInfo newData)throws DatabaseException, RemoteException;
public void delete(DataInfo toDelete)throws DatabaseException, RemoteException;
public void close() throws RemoteException;
public void lock(int record)throws IOException, RemoteException;
public void unlock(int record)throws RemoteException;
public DataInfo[] criteriaFind(String criteria) throws DatabaseException, RemoteException;
public String[] getComboValues(int fieldNum) throws DatabaseException, RemoteException;
public int getMatchCount(String matchCount) throws DatabaseException,RemoteException;
}
Heres the code DataClientLocal class
package suncertify.db;
import java.io.*;
import java.util.*;
public class DataClientLocal extends Data implements DataClient
{


public DataClientLocal(String dbname){
try
{
Data dbInstance = new Data(dbname);
}
catch(Exception ex)
{
System.out.println("Database connection failed");
}
}
}

I have 3 methods I defined in the Data class but I dont understand why it is looking for Data()???

C:\scjd\starting\suncertify\db\DataClientLocal.java:9: No constructor matching Data() found in class suncertify.db.Data.
public DataClientLocal(String dbname){
^
1 error
Process completed with exit code 1
Thanks Lisa
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added a empty constructor to Data Class and it now compiles fine any reason why I need a public Data(){}
in my Data Class to get my above DataClientLocal to compile?
Thanks Lisa
 
Aron J. Skantz
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lisa!
Yes, there is a good reason to why you need a empty constructor in the Data class.
If you extend a class and add a constructor to your new sub class as this:
public DataClientLocal(String dbname){
{some code}
}
then what really will be performed is this:
public DataClientLocal(String dbname){
super();
{some code}
}
Since super() tries to call an empty constuctor in Data and there isnt any, then the compilation will fail.
To solve this, add an explicit super(...) _on the first line of the new constuctor_ that matches one of the constructors in Data.
Regards
\Aron
[This message has been edited by Aron J. Skantz (edited March 16, 2001).]
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aron that makes alot of since. Totally forgot about the implicit constructor call thanks alot Lisa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic