• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Completely stumped

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Joe. Code is working fine. Cheers for the quick reply
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic