Wednesday, December 21, 2011

Eclipse settings

Eclipse settings are saved in the workspace/.metadata.


So for example my workspace is /gerardsetho/workspace,
then my Subclipse repository directories are stored in: 
/gerardsetho/workspace/.metadata/.plugins/org.tigris.subversion.subclipse.core/.svnProviderState


Might be useful when upgrading Eclipse versions (e.g. I wouldn't have to retype all the SVN repositories).

Wednesday, November 2, 2011

Null Object Reference in Flex 4's CrossDomainRSLItem

I just upgraded my computer and re-installed Eclipse and Flash Builder 4.5. And I ran into a familiar error:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/moduleInitHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:709]

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/moduleCompleteHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:718]

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::CrossDomainRSLItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:115]
at mx.core::FlexModuleFactory/getRSLInfo()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:493]
at mx.core::FlexModuleFactory/update()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:368]
at mx.core::FlexModuleFactory/timerHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\FlexModuleFactory.as:732]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()


The last error just kept repeating infinitely.

This happened before so I'm just writing this down that I won't forget again what the fix was.

In my case, this happened because my Flex compiled SWF was loaded by another Flex compiled SWF. No issues there. The issue was: the my SWF (lets call it "baby SWF") was compiled in Flex SDK 4.5. The other SWF ("papa SWF") was compiled in Flex 4.1. 

The solution is to recompile baby SWF using SDK 4.1. This is a 4 step process:
  1. download the Flex 4.1 SDK
  2. add the Flex 4.1 SDK to the list of Eclipse SDK
  3. change my baby SWF's project settings to use Flex 4.1
  4. recompile and deploy

#1. I downloaded it here: http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. I downloaded the "Adobe Flex SDK"

#2. In Eclipse preferences, under Flash Builder -> Installed Flex SDKs, click "Add". Browse to the Flex 4.1 SDK, and call it something sensible.

#3. In the baby SWF's project settings, under "Flex Compiler", select "Use a specific SDK" and select the 4.1 SDK.

#4. Happy developer...


Thursday, August 11, 2011

PostgreSQL server doesn't start in OS X

My PostgreSQL server is an EnterpriseDB product. It was installed using their installer. Suddenly one day, while watching a YouTube video, my computer hung. I had to restart OS X Snow Leopard (10.6), and after the restart, I couldn't connect to my PostgreSQL server: it wouldn't start. Even restarting Snow Leopard didn't help.


So I checked Snow Leopard's launchctl, which was responsible for starting processes at startup. 



sudo launchctl list |grep post
549 1 com.edb.launchd.postgresql-9.0




Not good. The second number tells me that postmaster has exited with a value of 1. Which most Unix users will know is an exit with error.



So OS X is launching the postmaster, but postmaster keeps exiting with an error. So what's the error? I'll try to launch postmaster in the exact same way that OS X is trying to launch, but I'll do it on the command line, so I can see the error myself.



First, I got to find the command that Launchctl uses. I thus open "/Library/LaunchDaemons/com.edb.launchd.postgresql-9.0.plist":



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
        <key>Label</key>
        <string>com.edb.launchd.postgresql-9.0</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Library/PostgresPlus/9.0SS/bin/postmaster</string>
                <string>-D/Library/PostgresPlus/9.0SS/data</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    <key>UserName</key>
    <string>postgres</string>
    <key>KeepAlive</key>
    <dict>
         <key>SuccessfulExit</key>
         <false/>
    </dict>
</dict>
</plist>


This tells me the command to run is "sudo /Library/PostgresPlus/9.0SS/bin/postmaster -D/Library/PostgresPlus/9.0SS/data". So I run that:



"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.



Ok. Can't execute that command as root. I know that PostgreSQL server is started under the user "postgres". So I try that:

sudo -u postgres /Library/PostgresPlus/9.0SS/bin/postmaster -D/Library/PostgresPlus/9.0SS/data

GMT FATAL:  lock file "postmaster.pid" already exists
GMT HINT:  Is another postmaster (PID 62) running in data directory "/Library/PostgresPlus/9.0SS/data"?


Ahhhh… Apparently another process has opened the pid lock file. Next step is to kill that offending process and try again. I can do it on the command line, but where possible, I try to do it using OS X's GUI :) Steve wants it done his way… So I open Activity Monitor, find PID = 62, and "Quit Process".

Everything is now fixed.


Tuesday, August 2, 2011

"An internal build error has occurred. Right-click for more information"

This has to be the most irritating compiler error description ever in the Flex compiler in Flash Builder 4 for Eclipse.


I opened up the "error log" view in Eclipse, and saw that Macromedia (now Adobe)'s parser was throwing an exception "java.lang.ClassCastException: macromedia.asc.parser.MetaDataEvaluator$KeyValuePair cannot be cast to macromedia.asc.parser.MetaDataEvaluator$KeylessValue"


No help there.


I then found the issue. In my case, it was a bad coding that was actually valid syntax:



private var fileLoadIsComplete = Boolean = false;



This should be 



private var fileLoadIsComplete : Boolean = false;



My only advice is to start commenting out recent code until you find the offending line that caused the "internal build error".

Tuesday, May 17, 2011

Bug "One or more constraints have not been satisfied"

I get the error message:


"Errors were encountered while creating the project.


Reason:
One or more constraints have not been satisfied"


This happens when I try to create a combined Java / Flex project using WTP (Web Tools Platform) in Eclipse 3.6 (Helios). Searching the Internet, this problem doesn't seem very widespread. Indeed a lot of people recommended to simply separate the Java side of the Flex Remote application and the Flex side of the Flex Remote application into 2 separate projects.


I have considered this, but I would still like to have both parts in the same Eclipse project. So how do I do this?


The idea is to not use the WTP wizard to create the combined Java / Flex project, but to do it manually myself. Below is a screen cast that will make it clear.






Here is a summary of what I did in the screen cast:

  1. create a Dynamic Web Project
  2. deploy to Glassfish
  3. copy BlazeDS jar files to WEB-INF/libs folder
  4. create WEB-INF/flex folder
  5. copy BlazeDS config files to WEB-INF/flex folder
  6. edit web.xml to deploy the BlazeDS MessageBroker servlet
  7. add Flex Project nature to the project, setting "bin-debug" as the output folder
  8. edit .settings 

In the screen cast, I paste some standard BlazeDS configuration. Here's what I pasted:





  <servlet>
  <servlet-name>MessageBrokerServlet</servlet-name>
  <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
  <init-param>
  <param-name>services.configuration.file</param-name>
  <param-value>/WEB-INF/flex/services-config.xml</param-value>
  </init-param>
  <init-param>
  <param-name>flex.write.path</param-name>
  <param-value>/WEB-INF/flex</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
  </servlet>


  <servlet-mapping>
  <servlet-name>MessageBrokerServlet</servlet-name> 
  <url-pattern>/messagebroker/*</url-pattern>
  </servlet-mapping>

Thursday, May 5, 2011

Changing the context root of a Dynamic Web Project in Eclipse

I always hated that when I created a Dynamic Web Project in Eclipse (I used 3.4 and 3.6), the context root of the deployed application was always the same as my project name. So I can't have a descriptive project name like 'The Company - concept test 1'. I'd have to have names like 'boc' as my Eclipse project name.


So now (yes, call me slow), I found out how I can dynamically change the context root that Eclipse will deploy my project application with.


When I create a Dynamic Web Project, a .settings folder would be automatically created for me. In that folder, in an XML file called: org.eclipse.wst.common.component, there will be elements called 'property'. One of those elements has a name-value attribute pair called 'context-root'. Change the value of that attribute, and republish your project.


Yes.

Monday, February 7, 2011

Obtaining a Java Date object for a Specific Time Zone

I want to get a java.util.Date object that represents a specific time at a specific time zone. Say "23:59 Wednesday 16 Feb 2011 EST"

TimeZone tz = TimeZone.getTimeZone("US/Eastern");
Calendar cal = Calendar.getInstance( tz );
cal.set(Calendar.YEAR, 2011);
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 16);
cal.set(Calendar.AM_PM, Calendar.PM);
cal.set(Calendar.HOUR, 11);
cal.set(Calendar.MINUTE, 59);
// cal.getTime() returns the Date for 23:59pm 16 Feb 2011 EST


Nice.

Friday, February 4, 2011

Add JVM options to Glassfish

I want to add a JVM option to Glassfish, so that when it will always start with the JVM option. Let's just say I want to add the below JVM option:


-Djava.awt.headless=true


2 ways to do it:


Glassfish Admin Console
By using the Glassfish Admin Console, we can easily add the required option. Just:

  1. go to http://my.glassfish.url:4848/ (the default port is 4848),
  2. login
  3. on the left select "Application Server"
  4. select the tab "JVM Settings"
  5. select the sub-tab "JVM Options"
  6. add your option there

XML Config
Go to the following Glassfish path on the file system:
/my/path/to/glassfish/domains/domain1/config
and edit the file domain.xml. Within that XML is an element called <java-config>. Within that element, add a child <jvm-options> with the option like so:

        <jvm-options>-Djava.awt.headless=true</jvm-options>

Done.


Thursday, January 27, 2011

Observer Design Pattern in Flex

Nice post here. A little ivory tower-ish, but interesting all the same.


Basically says, for the intents and purposes of those of us who actually do the coding, the Events system in Flex is the built-in Observer pattern.


We need to use more Observer-based custom components in Flex. Especially since Flex expects us to do so. I'm halfway through a pretty nice project right now, and I regret not taking the time to make my custom components. Instead, everything is now in 1 application MXML with custom components that are "1 level deep" if you get my meaning. I used to have the notion that, if code isn't sharable, then I can refactor that into a custom component later; let me just get it working first. 


I think now that even if code isn't sharable, I still need to create a new custom component. I need to dare to go deeper than "1 deep". For my sanity's sake.

Thursday, January 20, 2011

Note to self: Actionscript Strings are not Java Strings!

var s1: String = "gerard";
var s2: String = "gerard";
Alert.show( (s1 == s2).toString() );


In Actionscript the above displays true. Apparently there is a built in string comparison operator in Flash that compares the content, instead of the object references themselves.



This is actually intuitive. If I give anyone on the street 2 identical Bibles, and ask them "are they the same?", they would say "yes". Java devs will tell you their content is the same, but they are in fact 2 different instances of the books. 


I wonder what else is Java programming doing to my brain...

Wednesday, January 5, 2011

Installing iOS SDK

Here are the steps I took to install the iOS SDK.

  1. Checked my OS X version: I had 10.5 (Leopard)
  2. Found my Snow Leopard DVD
  3. Upgraded Leopard to Snow Leopard. I should have done this a long time ago.
  4. From the same Snow Leopard DVD, I installed Xcode 3.2
  5. Run Xcode
  6. Realized that the Xcode in the DVD did not include the iOS SDK
  7. Made angry noises
  8. Downloaded the iOS SDK. The version 4.2 is about 3GB. It includes Xcode 3.2.5, and the OS X SDK as well.
  9. Installed Xcode, iOS SDK, OS X SDK et al
  10. Realized the iOS SDK will take up more than 8GB on my Macbook
  11. Made incredulous noises
  12. After installation, I ran Xcode, and created a new project. And yes, I was able to create an iOS application.