Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / February 2005



Tip: Looking for answers? Try searching our database.

NSTimeZone null pointer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CyberSpiff - 23 Feb 2005 22:32 GMT
I must be doing something dramatically wrong here, but how could the
following Java snippet

NSTimeZone MyTimeZone = new NSTimeZone();

produce the following

Executable “QMeter” has exited with status 0.
[Session started at 2005-02-23 17:23:58 -0500.]
2005-02-23 17:24:05.491 QMeter[17673] java/lang/NullPointerException:
alloc or init returned nil
Stack Trace:
java.lang.NullPointerException: alloc or init returned nil
    at com.apple.cocoa.foundation.NSObject.allocateObjcObject(Native Method)
    at com.apple.cocoa.foundation.NSObject.<init>(NSObject.java:35)
    at com.apple.cocoa.foundation.NSTimeZone.<init>(NSTimeZone.java:295)
    at QMeterController.calcq(QMeterController.java:57)

I started using the NSGregorianDate object to be able to determine
differences between dates (and lazily avoiding having to figure out how
years,months, days,hours, etc manually), but when I tried using

NSTimeZone MyTimeZone = new NSTimeZone();
NSGregorianDate QDate = new NSGregorianDate(qYear, qMonth, qDay, qHour,
qMinute, qSecond, MyTimeZone.defaultTimeZone());

it generates the same error.

Any suggestions? Or is there a better way to calculate differences in
two dates?

Signature

-spiff
Never be bullied into silence. Never allow yourself to be made a victim.
Accept no one's definition of your life; define yourself.

Patrick Machielse - 23 Feb 2005 23:16 GMT
> I must be doing something dramatically wrong here, but how could the
> following Java snippet
[quoted text clipped - 7 lines]
> 2005-02-23 17:24:05.491 QMeter[17673] java/lang/NullPointerException:
> alloc or init returned nil

It's all in the _documentation_:

public NSTimeZone()

This constructor has been deprecated. Use any of the timeZone... static
methods instead.

patrick
CyberSpiff - 24 Feb 2005 00:01 GMT
>>I must be doing something dramatically wrong here, but how could the
>>following Java snippet
[quoted text clipped - 16 lines]
>
> patrick

Patrick, thank you for pointing that out. Trying to work through the
reams of documentation makes it very difficult at times.

One question I have to ask is, if something is deprecated, why do the
routines still compile? :-)

Thanks again for your patience and help.

Signature

-spiff
Never be bullied into silence. Never allow yourself to be made a victim.
Accept no one's definition of your life; define yourself.

Alwyn - 24 Feb 2005 07:04 GMT
> One question I have to ask is, if something is deprecated, why do the
> routines still compile? :-)

Well, 'deprecation' has a strange meaning in computing. In ordinary
parlance, if you deprecate something, you don't approve of it. In
computing parlance, it means that it is still supported, but its use is
discouraged, and it is not guaranteed to be supported in future.

Suppose you wrote:

NSTimeZone myTimeZone = NSTimeZone.defaultTimeZone();

will that solve your problem?

Alwyn
CyberSpiff - 24 Feb 2005 01:01 GMT
>>I must be doing something dramatically wrong here, but how could the
>>following Java snippet
[quoted text clipped - 16 lines]
>
> patrick

I hate to follow-up my own post, but I realized that if the NSTimeZone
is deprecated, then how do you use the NSGregorianDate class?

public NSGregorianDate(int year, int month, int day, int hour, int
minute, int second, NSTimeZone aTimeZone)

I assume you would use one of the other constructors, e.g.

public NSGregorianDate(double seconds)

Nu?

Signature

-spiff
Never be bullied into silence. Never allow yourself to be made a victim.
Accept no one's definition of your life; define yourself.

Patrick Machielse - 24 Feb 2005 10:00 GMT
> > It's all in the _documentation_:
> >
[quoted text clipped - 8 lines]
> public NSGregorianDate(int year, int month, int day, int hour, int
> minute, int second, NSTimeZone aTimeZone)

The above comment in the documentation says: don't use this constructor.
You _can_ use the class, but you must to use some other method to obtain
an instance of it. (Someone else pointed out how to call the static
method)

Generally when some method is declared 'deprecated' in Java, it means
that it has been superseeded by a better implementation, and has been
marked for removal in some future version of Java. Normally deprecated
methods still work, but the java compiler will draw your attention to
the fact that you are using old API (I believe this is the default
setting, if not: make it so).

In this case, Apple seems to have taken the concept a bit further than
Sun usually does: they have actively disabled the deprecated constructor
by returning a null value, thus forcing you to use the new API (and
breaking old binaries?)

Note: when I said 'it is all in the documentation' I spoke too soon. The
documentation of NSGregorianDate constructors happily shows an example
using new NSTimeZone()... I see now how you can get confused! A bug
report on the documentation seems to be in order.

patrick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.