Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha
Accepted Solution

setTimeInMillis(long) has protected access

Hi ppl,

 

I m using Calendar in a simple background application,In this, I hv retreive the current time from following function obtained from

 

                 long startTime = System.currentTimeMillis();

 

As, this returns time in milliseconds, I wn to set this in a calendar instance i.e.

                               Calendar c = Calendar.getInstance();

                               c.setTimeInMillis(Milliseconds);               ; //this line is giving err

 

But, this is on compilation giving an error, that setTimeInMillis(long) has protected access in java.util.Calendar. Plz. help !!

 

I m using JDE 4.6.1.23

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: setTimeInMillis(long) has protected access

That method is given for overriding purposes I suspect.. But you could create a Date with that long value.. And using setTime(Date date), you could set the date..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: setTimeInMillis(long) has protected access

Thnx mantaker for ur quick response...

 

Its working but actually I want to calculate the call duration b/w starting and ending of a call and this is not fulfilling my purpose, I hv tried this method but its not giving correct output:

 

  public String convertMilliSecondsToTime(long Milliseconds)
   {
             
       int HH = (int)(Milliseconds / (1000*60*60));
       int MM = (int)((Milliseconds % (1000*60*60)) / (1000*60));
       int SS = (int)(((Milliseconds % (1000*60*60)) % (1000*60)) / 1000);

       String time = HH + ":" + MM + ":" + SS;

 

    return time;

}

 

Can u plz. guide how to make it accurately...?

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: setTimeInMillis(long) has protected access

if you want a string, why don't use (simple)dateformat?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: setTimeInMillis(long) has protected access

Thnx simon,

 

Actually I was unable to find its import but nowI have got it at, by going thru some previous posts. Bu, would it help in calculating the difference also...?

 

                 import net.rim.device.api.i18n.SimpleDateFormat; 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: setTimeInMillis(long) has protected access

Absolutely yes!.. You could get System.currentMillis before and after call and then calculate the difference and then dividing it by thousand will get you the total seconds that is used.. No need for date format and all..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: setTimeInMillis(long) has protected access

Hi mantaker,

 

Thnx for the reply, I have got the time by System.currentMillis from callConnected method of AbstractPhoneListener but after call in callDisconnected method it returns null, as I know that the call is already disconnected so, how it can return the time...?? Now, I am getting little confused that will I have to make it all manually by using any thread..?? Or BB provides any simpler alternate way to perform this task..?

 

Anybody plz. guide me soon..? looking for ur response so, that I can proceed in my work with ur guidance...

 

Kanak :smileyhappy:

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: setTimeInMillis(long) has protected access

Are you saying System.currentTimeMillis() is returning null?  That method should always return a long value. Can you post some sample code where you are seeing this?

 

What BlackBerry Smartphone model and BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Trusted Contributor
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

Re: setTimeInMillis(long) has protected access

Hi,

this is what I'm doing, 

public void callConnected(int callId){

 

start = System.currentTimeMillis();

 

}

 

public void callDisconnected(int callId){

end = System.currentTimeMillis();

 

totalTime = (end-start)/1000;

 

String time = Long.toString(totalTime)

}

 

 

Unfortunately, this is giving me a wrong output, for e.g. if the total call duration was 10 seconds, I'm getting some weird output like 26, etc.

How could this be done effectively?

Thanks.

 

David

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: setTimeInMillis(long) has protected access

please create an own thread for your question, you can reference old threads if they are relevant.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter