I have written a method which reads all the records from address book
on Mac OS X.2 with the help of NSAppleScript class.
Some time code is running fine but sometime it generates
IllegalMonitorStateException. The print stack trace is given below:-
(please see the code after print stack trace)
A Buckyball Timer threw an exception:
java.lang.IllegalMonitorStateException: current thread not owner
at com.apple.mrj.macos.carbon.CarbonLock.release0(Native Method)
at com.apple.mrj.macos.carbon.CarbonLock.release(CarbonLock.java:43)
at com.apple.buckyball.app.Timer.EventLoopTimer(Timer.java:213)
at com.apple.cocoa.foundation.NSAppleScript.execute(Native Method)
at
com.inmarsat.mmi.launchpad.nativeresource.macx.MacXContacts.getContactsL
ist(MacXContacts.java:127)
Code is here:-
// reading each Contact item and creating a Contact object
public ArrayList getContactsList() throws ContactsException
{
System.out.println("inside getContactsList method");
// This line loads the Cocoa libraries.
// NSApplication.sharedApplication();
ArrayList contactsList = new ArrayList();
try
{
System.out.println("inside try block");
String script = "tell application \"Address
Book\""+"\n"
+ "set abList to every person"+"\n"
+ "set bigList to {}"+"\n"
+ "set bigListRef to a reference to
bigList"+"\n"
+ "repeat with i from 1 to count of
abList"+"\n"
+ "set abRecord to item i of abList"+"\n"
+ "set theID to (id of abRecord)"+"\n"
+ "set theName to (name of abRecord)"+"\n"
+ "set theEmail to \"NA\""+"\n"
+ "set thephone1 to \"NA\""+"\n"
+ "set thephone2 to \"NA\""+"\n"
+ "set themobile to \"NA\""+"\n"
+ "set theRemark to (note of abRecord as
string)"+"\n"
+ "if (count of emails of abRecord) > 0
then"+"\n"
+ "set theEmail to (value of first item of
emails of abRecord)"+"\n"
+ "end if"+"\n"
+ "if (count of phones of abRecord) > 0
then"+"\n"
+ "repeat with j from 1 to count of phones
of abRecord"+"\n"
+ "set thephone to item j of phones of
abRecord"+"\n"
+ "if (label of thephone = \"home\")
then"+"\n"
+ "set thephone1 to (value of thephone)"+"\n"
+ "end if"+"\n"
+ "if (label of thephone = \"work\")
then"+"\n"
+ "set thephone2 to (value of
thephone)"+"\n"
+ "end if"+"\n"
+ "if (label of thephone = \"mobile\")
then"+"\n"
+ "set themobile to (value of
thephone)"+"\n"
+ "end if"+"\n"
+ "end repeat"+"\n"
+ "end if"+"\n"
+ "set contact to {theID, theName,
thephone1, thephone2, themobile, theEmail," + "theRemark}
as list"+"\n"
+ "copy contact to the end of
bigListRef"+"\n"
+ "end repeat"+"\n"
+ "get bigList"+"\n"
+ "end tell";
System.out.println(script);
synchronized(this)
{
// This creates a new NSAppleScript object to
execute the script
NSAppleScript myScript = new
NSAppleScript(script);
// This dictionary holds any errors that are
encountered during script execution
NSMutableDictionary errors = new
NSMutableDictionary();
if (!strMobile.equals(""))
{
strPhone1 = strMobile ;
}
Contact contactData = new
Contact(strName,strEmail, strPhone1,strPhone2,
stType,strMobile,strRemark,strIndex,"");
contactsList.add(contactData);
}
}//end of synchronized block
Collections.sort(contactsList,new
AscendingComparator());
}
catch (Exception e )
{
throw new ContactsException(e.getMessage());
}
return contactsList ;
}
I have tried to even catch IllegalMonitorStateException but control is
not coming in catch block and it hangs the application.
please respond me as soon as possible.
Thanks and Regards,
Gaurav Gupta
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden