problem about initializer-Collection of common programming errors


  • ardavis
    ruby-on-rails deployment heroku initializer ruby-on-rails-3.1
    I’m trying to deploy my app to Heroku, I’ve done this before on my Windows machine, and now I am currently using a mac.I’m trying to use Postgresql for the first time.I have the following in my Gemfile:gem ‘pg’EDIT:AndrewDavis-OSX:lunchbox ardavis$ rvm listrvm rubies=> 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 ‘:’, expecting $end App::Application.config.session_store :c

  • John
    c++ arrays enums initializer
    class 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 : ‘{‘error C2334: unexpected token(s) preceding ‘{‘; skipping apparent function body

  • Peter Lawrey
    java performance static final initializer
    Before 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’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’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

  • tintinmj

  • Boon
    objective-c initializer
    This 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 */ – (id)initWithInfo:(NSDictionary *)info {self = [super init];if (self) {_info = info;}retu

  • Elazar
    c static malloc constants initializer
    I’m trying to initiate a static variable (inside a function) with malloc in C, but I’m getting the “initializer not constant error”. I know that I can’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’m creating and starting a new thread. I declare a pointer to

  • Andrew
    c# .net initializer
    I run into runtime NullReferenceException exception in the following code:public class Container {public IList<string> Items { get; set; } }class Program {static void Main(string[] args){var container = new Container() { Items = {“Test”} };} }It’s logical that compiller couldn’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

  • daviddeath
    c# object initialization compiler-warnings initializer
    Is it possible to enforce rules or throw an error when using object initializers in C#? I’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 = “New Years Party!”,Date = “Dec 31, 1999″// Show WARNING/ERROR here because no Location given

  • Joethemonkey101
    size cocos2d initializer
    I have a method where I’m taking a screenshot, but there’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 ‘-displaySize’ Oh and I’m using cocos2d…This is the entire method-(UIImage *)screenshot { CGSize displaySize = [[CCDirector sharedDirector] displaySize]; CGSize winSize = [[CCDirector sharedD

  • technomalogical
    c# linq object initializer
    Does 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?

  • dustmouse
    .net enums initializer
    I want to get an enum as an int, but only if it has an initializer applied to it – so that I know that the value was explicitly defined and isn’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 – I have the following mapping:Apples = 1, Bananas = 2, Pears = 4, Pineapples = 7I want to make sure that if the enum ispublic en

  • Slazer
    c++ list initialization initializer c++03
    I have a list<string> 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(“str1”)); myList.push_back(string(“str2”)); myList.push_back(string(“str3”)); etc. }I would like something like this:MyClass::MyClass():list(“str1″,”str2″,”str3”,etc.){ }

  • thorstenhirsch
    ruby-on-rails callback database-connection yaml initializer
    I’ve written my own yaml config file as described in railscast #85. APP_CONFIG[‘FOO’] works in the initializers (e.g. sidekiq.yml), but not in database.yml (error: undefined method ‘+’ for nil:NilClass; the ‘+’ is being used in a concatenation: APP_CONFIG[‘FOO’] + ‘bar’).Even putting APP_CONFIG into before_configuration did not solve this issue.Rails.application.config.before_configuration doAPP_CONFIG = YAML.load_file(“#{RAILS_ROOT}/config/config.yml”) endSame problem. APP_CONFIG is still causi

  • Pointy
    ruby-on-rails full-text-search initializer indextank searchify
    how do i access a variable from an initializer file?i have a file called search.rb in my initializer folderapi_client = IndexTank::Client.new ‘http://:[email protected]’ index = api_client.indexes ‘idx’however, in my controller whenever im trying to index a newly created lesson, rails gives me an error ofundefined method `document’ for nil:NilClassmy controller is…def createindex.document(@lesson.id).add({:text => @lesson.content }) endalso is this a bad way of indexing my docum

  • Nate Shoffner
    c# string field initializer
    I am not sure what exactly the issue is here. I am working with 2 strings and I keeping getting the error “A field initializer cannot reference the non-static field, method, or property ‘Captcha.Capture.CaptureTime'”.Here’s a snippet from the code:string CaptureTime = DateTime.Now.Month.ToString() + “-” + DateTime.Now.Day.ToString() + “-” + DateTime.Now.Year.ToString() + “-” + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();string SaveFormat = Prop

  • pixelearth
    ruby-on-rails activerecord initializer scoping
    I’ve tried to add a scope like this, via an initializerclass ActiveRecord::Base scope :this_month, lambda { where(:created_at => Time.now.beginning_of_month..Time.now.end_of_month) } endBut Im getting the error “NoMethodError: undefined method `abstract_class?’ for Object:Class”. What is the proper way to do this?

  • Petr Abdulin
    c arrays initialization initializer
    Consider following code:// hacky, since “123” is 4 chars long (including terminating 0) char symbols[3] = “123”;// clean, but lot of typing char symbols[3] = {‘1’, ‘2’, ‘3’};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.

  • baptzmoffire
    objective-c initialization xcode4.2 initializer
    Okay. Tough to find the best starting point, here. The error XCode (4.3.2) in Lion is kicking back to me is:Redefinition of ‘a’ with a different typeThe author says when we declare this line (near the bottom of this page, in main)…OwnedAppliance *a = [[OwnedAppliance alloc] init];…that it should run fine. It doesn’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’s

Web site is in building