Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

crashing problem due to buckyball timer exception in NSAppleScript class



Hi,

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();



// Execute the script!
NSAppleEventDescriptor results = myScript.execute(errors);
//System.out.println("errors = "+errors.toString());


if(errors.count()>0)
{
//System.out.println("errors = "+errors.toString());
String strMsg = (String)errors.objectForKey("NSAppleScriptErrorMessage");
System.out.println("error mesage = "+strMsg);
System.out.println("error number "+errors.objectForKey("NSAppleScriptErrorNumber"));
throw new ContactsException(strMsg);
}



int numberOfItems = results.numberOfItems();
System.out.println("Total Number of records in address book ="+numberOfItems);


                    String strIndex = "";
                    String strName = "";
                    String strPhone1 = "";
                    String strPhone2 = "";
                    String strMobile = "";
                    String strEmail = "";
                    String strRemark = "";

for(int i = 1; i <= numberOfItems; i++)
{
NSAppleEventDescriptor subDescriptor = results.descriptorAtIndex(i);
strIndex = subDescriptor.descriptorAtIndex(1).stringValue();
strName = subDescriptor.descriptorAtIndex(2).stringValue();
strPhone1 = subDescriptor.descriptorAtIndex(3).stringValue();
strPhone2 = subDescriptor.descriptorAtIndex(4).stringValue();
strMobile = subDescriptor.descriptorAtIndex(5).stringValue();
strEmail = subDescriptor.descriptorAtIndex(6).stringValue();
strRemark = subDescriptor.descriptorAtIndex(7).stringValue();


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

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.