• Post Reply Bookmark Topic Watch Topic
  • New Topic

Completely stumped

 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I have a quick query in relation to Java logging functionality (java.util.logging). I know this may not be the best place to post this meassage but here goes anyway. In Java logging there is a Class LogRecord which has one constructor taking two parameters, i.e.

LogRecord(Level level, String msg)

I am simply trying to extend this LogRecord class so that I can add my own methods and so on to the subclass as is standard in inheritance. However when I try to create a subclass called MyLogRecord, I keep encountering the following error:

constructor LogRecord() not found in class java.util.logging.LogRecord

The MyLogRecord class appears as follows.

import java.util.logging.LogRecord;
import java.util.logging.*;

public class MyLogRecord extends LogRecord
{}

I have reduced this class to a mere couple of lines of code, as it appears above, but I am still getting the same error. Can anyone please help. joe
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the wonderful world of inheritance. There are a couple of rules that Java enforces to keep objects in a consistent state. The first is: if you do not create a constructor, the compiler will create a no-argument constructor for you. The second is: If you do not make a call to the superclass constructor in your constructor, a call will be made to the superclass' no-argument constructor for you. So your class actually looks like this:


Now if one creates a constructor in their class, the compiler does not create the no-argument constructor. You know that java.util.logging.LogRecord has a single constructor that takes two arguments. Your class is attempting to invoke a constructor with no arguments so the compiler gives an error.
 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Joe. Code is working fine. Cheers for the quick reply
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!