• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Calendar/Protected Access Help Please

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am trying to write a small program that will take a string input, look at the length, parse it as an int value, then feed that value to a GregorianCalendar object as milliseconds, then display the corresponding date.

Here is the code for the ActionListener:

private class dateAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String f = input.getText();
int inCode = 0;

if (f.length() <= 9) inCode = Integer.parseInt(f.trim(), 16);
else
{
inCode = Integer.parseInt(f.trim());
}

Time mDate = new Time(inCode);
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(inCode);
calendar.computeFields();


f = calendar.MONTH + " " + calendar.DAY_OF_MONTH + ", " + calendar.YEAR;

output.setText(" " + f);
}
}

This code gives me the following compile time error:

HexVerify.java:79: computeFields() has protected access in java.util.GregorianCalendar
calendar.computeFields();
^
I have looked up protected access and I guess I just don't understand what it's saying well enough to see why I am getting the error.

Can someone enlighten me?

Thanks,

Glen
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like it is used internally by Calendar/GregorianCalendar. It's protected, so subclasses and classes in the same package have access to it.

Why did you think you need to call it?


calendar.setTimeInMillis(inCode);
calendar.computeFields();



I peeked at the source for Calendar and computeFields() is called by setTimeInMillis()
[ February 10, 2005: Message edited by: Carol Enderlin ]
 
Glen A Scheel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added it into the code because I thought that a different problem was being caused by the setTimeInmillis not updating the other fields. However , it now looks like it was because I was using the wrong datatype for my input field.

Thanks for looking into it for me. I believe that I have it working properly now.

Glen
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic