{"id":5440,"date":"2014-03-30T21:59:35","date_gmt":"2014-03-30T21:59:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-initializer-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:59:35","modified_gmt":"2014-03-30T21:59:35","slug":"problem-about-initializer-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-initializer-collection-of-common-programming-errors\/","title":{"rendered":"problem about initializer-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/03fb59bf27824bdd9e12b461b5f1c117?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nardavis<br \/>\nruby-on-rails deployment heroku initializer ruby-on-rails-3.1<br \/>\nI&#8217;m trying to deploy my app to Heroku, I&#8217;ve done this before on my Windows machine, and now I am currently using a mac.I&#8217;m trying to use Postgresql for the first time.I have the following in my Gemfile:gem &#8216;pg&#8217;EDIT:AndrewDavis-OSX:lunchbox ardavis$ rvm listrvm rubies=&gt; ruby-1.9.2-p180 [ x86_64 ]AndrewDavis-OSX:lunchbox ardavis$ heroku rake db:migrate rake aborted! \/app\/config\/initializers\/session_store.rb:3: syntax error, unexpected &#8216;:&#8217;, expecting $end App::Application.config.session_store :c<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6c3935e8e58cdd1c3c970c54d81d6688?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJohn<br \/>\nc++ arrays enums initializer<br \/>\nclass ARouter {enum directions {north, neast, east, seast, south, swest, west, nwest};static directions gon[] = {north, neast, nwest, east, west, seast, swest, south}; };Hi, does anyone know what is the matter with the above code?I am getting 2 errors for the second line from VC++2008Ex:error C2059: syntax error : &#8216;{&#8216;error C2334: unexpected token(s) preceding &#8216;{&#8216;; skipping apparent function body<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/53ee9941b3fefef67175daf212e62d41?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPeter Lawrey<br \/>\njava performance static final initializer<br \/>\nBefore I ask my question can I please ask not to get a lecture about optimising for no reason. Consider the following questions purely academic.I&#8217;ve been thinking about the efficiency of accesses between root (ie often used and often accessing each other) classes in Java, but this applies to most OO languages\/compilers. The fastest way (I&#8217;m guessing) that you could access something in Java would be a static final reference. Theoretically, since that reference is available during loading, a good<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dce6c0950aede1105045e3c9365c4aed?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntintinmj<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2cfc9cb28eb13f936a20776d10e3b0f3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBoon<br \/>\nobjective-c initializer<br \/>\nThis question already has an answer here:Is it possible to make the -init method private in Objective-C?5 answersBest way of preventing other programmers from calling -init4 answersI have created a different init method and would like that to be the designated initializer instead of the standard -init. How can I prevent client code from instantiating the class using -init?e.g.\/* everyone must call this *\/ &#8211; (id)initWithInfo:(NSDictionary *)info {self = [super init];if (self) {_info = info;}retu<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/F51FU.jpg?s=32&amp;g=1\" \/><br \/>\nElazar<br \/>\nc static malloc constants initializer<br \/>\nI&#8217;m trying to initiate a static variable (inside a function) with malloc in C, but I&#8217;m getting the &#8220;initializer not constant error&#8221;. I know that I can&#8217;t initiate a static with non constants in C, but can anyone think of a solution? I need the code to have the same effect as this:static int *p = (int *)malloc(sizeof(int));Is there a trick\/workaround?EDIT: I have a function that is called every time a flag goes high. In this function, I&#8217;m creating and starting a new thread. I declare a pointer to<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/142dbbce38e59d6b5e452ca6fcf725ef?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAndrew<br \/>\nc# .net initializer<br \/>\nI run into runtime NullReferenceException exception in the following code:public class Container {public IList&lt;string&gt; Items { get; set; } }class Program {static void Main(string[] args){var container = new Container() { Items = {&#8220;Test&#8221;} };} }It&#8217;s logical that compiller couldn&#8217;t create interaface instance but I got a runtime exception, not a compile time. I was confused even more when I investigated this behavior further:var container = new Container() { Items = {} }; \/\/Legal, Items is nul<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0e1898255abb065ea84258e0d1ecf377?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndaviddeath<br \/>\nc# object initialization compiler-warnings initializer<br \/>\nIs it possible to enforce rules or throw an error when using object initializers in C#? I&#8217;d like to throw a compiler error or warning if an object is initialized but is missing a certain property.public class Party {public string Name { get; set; }public string Date { get; set; }public Location Location { get; set; } }public class SignUpForParty {public void DoSomething(){Party party = new Party(){Name = &#8220;New Years Party!&#8221;,Date = &#8220;Dec 31, 1999&#8243;\/\/ Show WARNING\/ERROR here because no Location given<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d7409ad039d6bb02bcbe2c540e6b5c94?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJoethemonkey101<br \/>\nsize cocos2d initializer<br \/>\nI have a method where I&#8217;m taking a screenshot, but there&#8217;s 2 problems with it. For the 2 linesCGSize displaySize = [[CCDirector sharedDirector] displaySize]; CGSize winSize = [[CCDirector sharedDirector] winSize];I get the warning Invalid initializer for displaySize, and also CCDirector may not respond to &#8216;-displaySize&#8217; Oh and I&#8217;m using cocos2d&#8230;This is the entire method-(UIImage *)screenshot { CGSize displaySize = [[CCDirector sharedDirector] displaySize]; CGSize winSize = [[CCDirector sharedD<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7facd6a5ff245d8c71824fec6e7e73d6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntechnomalogical<br \/>\nc# linq object initializer<br \/>\nDoes anyone have any tips for debugging exceptions in a C# object initializer block? The object initializer syntax is basically all or nothing, which can make it especially difficult to troubleshoot inside of a LINQ query. Short of breaking the object creation out to a separate method, is there anything I can do to see which property setter is throwing an exception?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/qhTIW.png?s=32&amp;g=1\" \/><br \/>\ndustmouse<br \/>\n.net enums initializer<br \/>\nI want to get an enum as an int, but only if it has an initializer applied to it &#8211; so that I know that the value was explicitly defined and isn&#8217;t just the default value. This is because I am using enums to represent a mapping with defined int codes. Is there a way to do this with enums, or am I going to have to use something else like a dictionary?Here is an example &#8211; I have the following mapping:Apples = 1, Bananas = 2, Pears = 4, Pineapples = 7I want to make sure that if the enum ispublic en<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/edd61ce7298383d8686c8fecb14b5708?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSlazer<br \/>\nc++ list initialization initializer c++03<br \/>\nI have a list&lt;string&gt; myList as a private attribute of my class. The content of this list is known at compile time and is constant. Is there any compact way (in C++03) to initialize its value? I can only think of this:MyClass::MyClass(){ myList.push_back(string(&#8220;str1&#8221;)); myList.push_back(string(&#8220;str2&#8221;)); myList.push_back(string(&#8220;str3&#8221;)); etc. }I would like something like this:MyClass::MyClass():list(&#8220;str1&#8243;,&#8221;str2&#8243;,&#8221;str3&#8221;,etc.){ }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/388d34810533e8214bc3ac8dde1c2ebe?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nthorstenhirsch<br \/>\nruby-on-rails callback database-connection yaml initializer<br \/>\nI&#8217;ve written my own yaml config file as described in railscast #85. APP_CONFIG[&#8216;FOO&#8217;] works in the initializers (e.g. sidekiq.yml), but not in database.yml (error: undefined method &#8216;+&#8217; for nil:NilClass; the &#8216;+&#8217; is being used in a concatenation: APP_CONFIG[&#8216;FOO&#8217;] + &#8216;bar&#8217;).Even putting APP_CONFIG into before_configuration did not solve this issue.Rails.application.config.before_configuration doAPP_CONFIG = YAML.load_file(&#8220;#{RAILS_ROOT}\/config\/config.yml&#8221;) endSame problem. APP_CONFIG is still causi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b19917aa04a6839aef577f1117c71d48?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPointy<br \/>\nruby-on-rails full-text-search initializer indextank searchify<br \/>\nhow do i access a variable from an initializer file?i have a file called search.rb in my initializer folderapi_client = IndexTank::Client.new &#8216;http:\/\/:xxyyzz@xv9v.api.searchify.com&#8217; index = api_client.indexes &#8216;idx&#8217;however, in my controller whenever im trying to index a newly created lesson, rails gives me an error ofundefined method `document&#8217; for nil:NilClassmy controller is&#8230;def createindex.document(@lesson.id).add({:text =&gt; @lesson.content }) endalso is this a bad way of indexing my docum<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7b36cd1823a4df394db58bde9f7edfab?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNate Shoffner<br \/>\nc# string field initializer<br \/>\nI am not sure what exactly the issue is here. I am working with 2 strings and I keeping getting the error &#8220;A field initializer cannot reference the non-static field, method, or property &#8216;Captcha.Capture.CaptureTime'&#8221;.Here&#8217;s a snippet from the code:string CaptureTime = DateTime.Now.Month.ToString() + &#8220;-&#8221; + DateTime.Now.Day.ToString() + &#8220;-&#8221; + DateTime.Now.Year.ToString() + &#8220;-&#8221; + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();string SaveFormat = Prop<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fbbd46a6f03489e1724c2dbf50c6a98c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npixelearth<br \/>\nruby-on-rails activerecord initializer scoping<br \/>\nI&#8217;ve tried to add a scope like this, via an initializerclass ActiveRecord::Base scope :this_month, lambda { where(:created_at =&gt; Time.now.beginning_of_month..Time.now.end_of_month) } endBut Im getting the error &#8220;NoMethodError: undefined method `abstract_class?&#8217; for Object:Class&#8221;. What is the proper way to do this?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9dfecf03d8106728f8bb324b201ebf1f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPetr Abdulin<br \/>\nc arrays initialization initializer<br \/>\nConsider following code:\/\/ hacky, since &#8220;123&#8221; is 4 chars long (including terminating 0) char symbols[3] = &#8220;123&#8221;;\/\/ clean, but lot of typing char symbols[3] = {&#8216;1&#8217;, &#8216;2&#8217;, &#8216;3&#8217;};so, the twist is actually described in comment to the code, is there a way to initialize char[] with string literal without terminating zero?Update: seems like IntelliSense is wrong indeed, this behaviour is explicitly defined in C standard.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cfb80129cbe7b3ac39e529ebc0dace77?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbaptzmoffire<br \/>\nobjective-c initialization xcode4.2 initializer<br \/>\nOkay. Tough to find the best starting point, here. The error XCode (4.3.2) in Lion is kicking back to me is:Redefinition of &#8216;a&#8217; with a different typeThe author says when we declare this line (near the bottom of this page, in main)&#8230;OwnedAppliance *a = [[OwnedAppliance alloc] init];&#8230;that it should run fine. It doesn&#8217;t. It kicks back the error above. I understand that, because OwnedAppliance has no init method in its implementation, the compiler will go up the hierarchy to OwnedAppliance&#8217;s<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ardavis ruby-on-rails deployment heroku initializer ruby-on-rails-3.1 I&#8217;m trying to deploy my app to Heroku, I&#8217;ve done this before on my Windows machine, and now I am currently using a mac.I&#8217;m trying to use Postgresql for the first time.I have the following in my Gemfile:gem &#8216;pg&#8217;EDIT:AndrewDavis-OSX:lunchbox ardavis$ rvm listrvm rubies=&gt; ruby-1.9.2-p180 [ x86_64 ]AndrewDavis-OSX:lunchbox ardavis$ heroku [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5440","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5440"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5440\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}