Gregory's Blog

ColdFusion arrays can't use zero as an index.

I should have known better, but I had forgot that you can't use a zero as an index when constructing a ColdFusion array. On this blog, I have 14 different themes, and 39 settings for each theme, and created an array stored in the application scope to store the values in. I wanted to use a zero as an index to identify the name of the theme, and then use 1 through 39 as the theme setting. However, when I tried this approach I received the following error: "A scalar value of type java.lang.String cannot be assigned to a 2-dimensional ColdFusion array." The problem was solved when I used 1 instead of 0 as the first index. I have always thought that this was odd as assigning a zero index should work. Most other languages default to a zero on the first array item, and still mistakenly assumed that this would work here.

Here was my original code that caused this error:

view plain about
1<!--- Theme --->
2<cfset application.arrThemeSettingsFromIniStore[1][0] = "black"><!--- black --->
3<!--- Theme variables --->
4<cfset application.arrThemeSettingsFromIniStore[1][1] = trim(getSettingsByTheme('black').useCustomTheme)><!--- useCustomTheme --->
5more custom theme settings...

The code should not use a zero based index like so:

view plain about
1<!--- Theme --->
2<cfset application.arrThemeSettingsFromIniStore[1][1] = "black"><!--- black --->
3<!--- Theme variables --->
4<cfset application.arrThemeSettingsFromIniStore[1][2] = trim(getSettingsByTheme('black').useCustomTheme)><!--- useCustomTheme --->
5more custom theme settings...

This entry was posted on May 25, 2019 at 12:31 AM and has received 26 views.

There are currently 0 comments.

Your input and contributions are welcomed!

If you have an idea, BlogCfc based code, or a theme that you have built using this site that you want to share, please contribute by making a post here or share it by contacting us! This community can only thrive if we continue to work together.

Images and Photography:

Gregory Alexander either owns the copyright, or has the rights to use, all images and photographs on the site. If an image is not part of the "Gregory's Blog" open sourced distribution package, and instead is part of a personal blog post or a comment, please contact us and the author of the post or comment to obtain permission if you would like to use a personal image or photograph found on this site.


Portions of Gregory's Blog are powered on the server side by BlogCfc, an open source blog developed by Raymond Camden. Revitalizing BlogCfc was a part of my orginal inspiration that prompted me to design this site. Some of the major open source contributers to BlogCfc include:

  1. Peter Farrell: the author of 'Lyla Captcha' that is used on this blog.
  2. Pete Freitag: the author of the 'ColdFish' code formatter that is also used on this blog.


Gregory's Blog Version 1.01 June 13, 2019 00:49 PST.