FAQ Database Discussion Community


Deploying existing Elastic Beanstalk inside VPC without deleting the RDS associated

amazon-web-services,static,elastic-beanstalk,vpc
I've currently in production a beanstalk with loadbalanced instances, and an associated RDS. Also got some routing/dns configuration that allow me to call my beanstalk with a "straight" domain name. I'm in the need to assign a static IP my Elastic Beanstalk Application so I can give it to a...

PHP - Using a Double colon with a class varible

php,class,static,scope-resolution
I'm trying to call a static function with a varible name from a class. The desired outcome: class Controller extends Controller { public $model = 'ModelName'; public function index() { $woot = $this->model::find(''); var_dump($woot); } } This works: $class = 'ClassName'; $object = $class::find($parameters); This works too: $class = new...

Change static variable

swift,static,global-variables
im new in swift. I'd like to ask u if i go the right way. I have something like this: class ViewController: UIViewController { struct myVars { var static short_text = "" } override func viewDidLoad() { super.viewDidLoad() loadData() println(short_text) } func loadData() { myVars.short_text = "Hello world!" } }...

Using external static library in LPCXpresso

static,libjpeg,lpc
I am using the LPCXpresso IDE to program my microcontroller to use the libjpeg library for a particular application. However, I cannot seem to get the LPCXpresso IDE to recognize libjpeg. The way I see it, there are two options: 1) Take the jpeglib.a file, include it as an external...

Thread creation inside constructor

c++,multithreading,static,pthreads
So, I am using C++11 and I made a class Class C { private: queue<std::int> s; pthread_t x; public: C() {phthread_create(&x, NULL, d_q, NULL); void log(int p); // pushes into q. void* d_q(void* q); // this is a function which will pop s. assume s is thread safe. } The...

django1.8 cannot include css, js files in template

html,css,django,static,django-1.8
I created a "testproject" using django 1.8. The CSS, JS, Images are not working. I included template, css and js folder outside project folder like this: My project folder is : /home/myuser/testproject/ My media folder is : /var/www/test_media/ template (folder) css (folder) js (folder) settings.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))...

C - how to keep variable

c,static,int
I would like know how I can keep the text in the txt variable? I would like to keep it unitl my function will end - I think it's called static int #include <stdio.h> #include <stdlib.h> int main() { char buf[1024]; char txt[100]; printf("Insert a text: "); fgets(txt, 100, stdin);...

Placing a global constant array into `.rodata` section

c,gcc,static
The goal is to place a large array of constant data into .rodata section with allowing the access to it from other translation units. As far as I know, GCC would place a data into the read-only section if declared as static const. But then it is impossible to declare...

C# singleton pattern in a static class?

c#,static,singleton
My event dispatcher class loosely couples instances of other classes by implementing sort of signals-slots design pattern. Only one unique event dispatcher is supposed to exist in an application. Since my Dispatcher class – which does all the work – inherits from Dictionary<TKey, TValue>, it cannot be declared static. To...

Initialisation of Static variables in java

java,static
I was asked this question in an interview If you do something like this, private int c = d; private int d; It results in compile-time error that you Cannot reference a field before it is defined. Coming to the interview question, 1 public static int a = initializeStaticValue(); 2...

static member variable initializing twice

c++,static,initialization
I'm using my own REGISTER_OBJECT() macro to create a factory full of classes. It works as expected, except for the initialization of my static std::map variable. If I don't initialize the static std::map in a .cpp file, I'll of course get a unresolved external symbol. But the problem is, I...

nesting classes in Java and referencing them in static main

java,static,nested
If the class Animal is nested inside Test, I get the error: "non-static variable this cannot be referenced from a static context" Can you please explain this error and offer a way to make this code work, while still keeping nested classes? I'd like to learn to work with nested...

Meteor - Router.go() doesn't run when passed a variable

templates,meteor,static,path,iron-router
I have a template for a back button I've been reusing: <template name="btnBack" label="" path=""> <a href="" data-path="{{path}}" class="btn btn-info btn-small" role="button"> <span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> {{label}} </a> </template> I pass it two fields, label and path statically. My intention is to pass the static path field to Iron-Router to...

How to show posts onto a static page

ruby-on-rails,static,posts
I have created a image uploading type website. I can login and upload images and it shows perfectly. But I want to create a landing page for users who are not logged in and can see few images on the landing page. And whenever someone uploads an image, it should...

C: Variable turns to 0 simply calling getline inside for loop

c,variables,for-loop,static,getline
In the following code (simplified version of my source code) the variable lv which is initialized to 1 right when declared, mysteriously turns to 0 when getline is called inside the for loop. You may notice it from the printf if you enter anything but "cl", or via gdb. The...

Using NON static class Methods Without reference

java,object,methods,reference,static
I'm new to Java. I know the concept of static and non static method. I'm wondering if it's possible to use non static methods of a class without having to create a reference to it. Like for example, for my program I'm working with Date objects, and I need to...

java test objects with static field

java,unit-testing,static
I have the object with static field: class Project() { private static id; private int projectid; public Project(fileds) { this.id = id++; } //methods } Now I want to test this class with multiple tests. The problen is that my objects are not deleted from memory when one test is...

Emergency: “error: non-static variable this cannot be referenced from a static context” [duplicate]

java,static,this,non-static
This question already has an answer here: non-static variable cannot be referenced from a static context 10 answers I have 4 hours to complete my exercise but I get multiple "cannot be referenced from a static context" errors. Here are these in full: MainApp.java:281: error: non-static variable this cannot...

Android:I do not understand: static { foo();} [duplicate]

java,android,static,static-block
This question already has an answer here: Static initializer in Java 8 answers Static Block in Java [duplicate] 7 answers Sometimes I see something like it, in a class in Android: static { foo(); } What does this do? Why? ...

OCP Java SE 6 Practice Questions - WeatherTest Enum

java,enums,static,ocp
A question in "OCP Java SE 6 Programmer Practice Exams (Exam 310-065)" Assesment test 2. Given: public class WeatherTest { static Weather w; public static void main(String[] args) { System.out.print(w.RAINY.count + " " + w.Sunny.count + " "); } enum Weather { RAINY, Sunny; int count = 0; Weather() {...

Encapsulate dependency/coupling and hierachy of static data list

c#,static,decoupling
Apologies for the title, I really don't know what to call this problem. I have an abstract class which describes the interface of some data collection. I would like to retrieve an instance list of all classes that derives from this, without littering the base class or the code that...

Recursive initialization : Static Initializer not getting called when i access Class field

java,static,classloader
Understanding about loading a class and calling static initializer In what order do static initializer blocks So, I just tried to confirm it - public class OOMErrorB extends OOMErrorA { public static int c = 10; static { System.out.println("Loading static B " + c); System.out.println(OOMErrorA.a); } public static void main(String[]...

Static Class Template member initialization

templates,c++11,visual-c++,static,msvc12
I have an issue when trying to initialize static members of a static class template. Basically, what I thought this approach would be useful for: I have a lot of objects, which are of course all of the same Base type but they have differing object types. I just want...

Primitive type and reference type objects

c#,static,primitive-types,reference-type
I have an exam question from a past paper that I'm trying to answer: Discuss variables of type primitive, reference and static in the context of a programming language. Give suitable examples [8]. The answer I have so far is: A primitive type is an object which the language has...

Is there a way to get the object which called my static method as an instance method? [duplicate]

java,static
This question already has an answer here: Reflection: get invocation object in static method 4 answers We all know that in Java you can call a static method as an instance method like this: Foo foo = new Foo(); FooBar fooBar = foo.bar(); // bar is a static method...

Definition of private weak_ptr in template class

c++,templates,static
First of all: I am new to C++, so don't judge me. :) I tried defining a static weak_ptr in a template class in order to use it over all instances. This is my code: template <class T> class my_template : public my_class { protected: std::shared_ptr<T> sp; virtual bool...

Is it possible to initialize a static member variable after running the main?

c++,static
Test.h class Test { static int i; }; Test.cpp int Test::i = 1; I know that normally we initialize a static member as above. And the static member is initialized before the function main runs. My question is: Is it possible to initialize the static member after the function main...

How do I avoid problems arising from accessing static fields before the class is initialized?

java,static,classloader
I have this code: public abstract class Person { public static final class Guy extends Person { public static final Guy TOM = new Guy(); public static final Guy DICK = new Guy(); public static final Guy HARRY = new Guy(); } public static final List<Guy> GUYS = ImmutableList.of(Guy.TOM, Guy.DICK,...

C++: static instance of inner class in outer class

c++,static,inner-classes
I have written some piece of code as below. Here there is an outer class and an inner class. I want a functionality similar to inner static class of java. So I declare the inner class object as static. The output comes fine: #include <iostream> using namespace std; class X...

How can I differentiate static functions with nm or readelf output in C

c,static,nm,symbol-table
I am trying to process the output of a nm or readelf -s on an executable. However, I am having trouble differentiating static functions from each other in the output. Here is what I am working with: test.c static int foo() { int x = 6; } main() {} other.c...

Static util class with Spring, unsure if I should make it a SpringBean, design concerns

java,spring,spring-mvc,static
Quick high level concept of my design.. CLI tool to create AWS EBS snapshots CLI tool just calls Java class com.util.SnapshotUtil com.util.Snapshot calls AWS Interfacing class com.aws.AWSAdapter example usage from command line.. cli-tool create-snapshot.. calls java class eventually calling below method SnapshotUtil.createSnapshot() // statically call AWSAdapter.createSnapshot(); Currently everything is static...

Calling a Static Method In Main

java,methods,static,rational
How do call the last method on this class, in main? I am just trying to return a new Rational object that contains the product of the two parameters. Every time I try to call it in main, I can't use integer in the parameters, since it only accepts objects....

Call Javascript function from C# static web method (page method)

javascript,c#,asp.net,static,webmethod
I used: ScriptManager.RegisterStartupScript(this, GetType(), "", "MyJSFunction('parameter')", true); to reach the MyJSFunction function in JavaScript from Page_Load and it worked fine. Now I'm in need of calling lets say the same function but from a static web method, but I get these 2 errors on this & GetType(): this: Keyword 'this'...

Is this thread-safe in Java?

java,static,thread-safety
Is the following static method "contains" safe from a visibility perspective? public class MyTest { private static final HashSet<String> mySet= new HashSet<String>(); static { mySet.add("cat"); mySet.add("dog"); mySet.add("bird"); } public static boolean contains(String key) { return mySet.contains(key); } } So then if multiple threads call MyTest.contains(string) are they guaranteed to see...

Java dynamic, static casting

java,dynamic,static,polymorphism
import javax.swing.*; public class Toast { static Object[] objects = { new JButton(), new String("Example"), new Object() }; public static void main(String[] args) { System.out.println( new Count(objects) ); for (Object o : objects) System.out.println(o); } } class Count { int b, s, o; public Count(Object[] objects) { for (int i=0;...

static and final static assignment

java,variables,static,variable-assignment,final
I was using same kind of concept , I used in first class. b was initialized to 0 and I got 0 everywhere I used b. After some time I got the reason and ran debugger and saw a has not been allocated any value till function call.variable a has...

Implementing a Command Design Pattern with static methods C#

c#,design-patterns,design,static
I know how to implement a Command Design pattern as follows: public abstract class Command { public abstract void Execute(string someString); } Say I inherit this ,as an example: public class ConnectionCommand : Command { public override void Execute(string connectionString) { ...do some stuff here...; } } Problem is to...

Static interface equivalent C#

c#,inheritance,interface,static
I've worked with singletons in the past and I'm aware it's a solution for some people who are trying solve the static interface problem. In my case, I can't really use a singleton because I have an external class that I'm inheriting from and I have no control over this...

Why is a static method considered a method?

java,methods,static,terminology
I am writing an explanation for some code for a course, and have been accidentally using the words method and function interchangeably. I decided to go back over and fix the wording, but ran into a hole in my understanding. From what I understand, a subroutine is a function if...

about usage of “static”, really basic

c,static
#include<stdio.h> int a; int fun(int b) { static int c=3; return ((++a)+(++b)+(++c)); } Main() { int i,a=2; for(i=0;i<2;i++) printf("%5d",fun(a)); } I think answer is 1012 but don't have comp I wanna know progress...

How to get a variable from another class without calling a constructor?

java,constructor,static,libgdx,box2d
So, in LibGDX I am using box2d and I have a class for contact listening. I need to get my player's body without making a class object, because it will call the constructor the second time. And a static variable is not an option. How should I do this? Here...

Javascript static vs instance, prototype keyword

javascript,static,prototype
I want to know the difference between the following two code snippets What I understand is this is static because without creating an instance with new keyword, getCookie and setCookie functions can be called. var CookieHandler = function () {}; CookieHandler.getCookie = function (key) { }; CookieHandler.setCookie = function (key,...

Static method file path [duplicate]

java,static,absolute-path
This question already has an answer here: Different ways of loading a file as an InputStream 4 answers How do i get the Path of a file in the same package as the class? This doesn't work. public static void SaveAllMockData() throws Exception { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("mockdata.json"); }...

Nginx express static files not found

file,express,nginx,static
I am trying to serve static contents with nginx instead of express. Nginx server block static file part is location / { root /var/www/analytics/web/static; try_files $uri $uri/ @analytics_web; expires off; add_header Cache-Control no-cache; } The static resources are in /var/www/analytics/web/static and they get served if i include app.use('/static', express.static(app.get('config').paths.static)); in...

“Only static constant integral variables may be initialized within a class ”

c++,class,variables,static
can someone explain to me why cant i initialize a static variable inside the class ? what happens in compilation time exactly ? for example : class Object { static int numberOfObjects = 0; // This gives the error Object(){ nummberOfObjects++; } }; Thanks !...

Is there a way to access the variables/fetch the assigned values of the caller class in a method of the called class?

java,class,static
This is similar to the question : Is there a way to access the variables of the calling class in a method? But I am not quite able to get the exact answer. What I am trying to do: class A{ m() { int a=8; new B.m1(); } } class...

std::string vs char array for static const

c++,arrays,static
I want to use a string constant in multiple places in my cpp file. Should I use std::string or char[]? static const std::string kConstantString = "ConstantStringValue"; static const char kConstantString[] = "ConstantStringValue"; I was told to prefer the latter since it "avoids static allocation". Doesn't the char array also have...

Static fields in Android

java,android,static
I am newbie in android and java development and i want to understand some things. Is it bad practice to use static field for transfer data between activities and fragments? For me, it is much easier than using extras in intents. Why many programs use context as parameter in constructors...

Django static files 404 on server, although working locally

python,django,apache,static
I have deployed a django application on an apache server using WSGI but the static files give me 404 errors although everything worked fine on my PC using Django's development server. My apache2.conf: WSGIScriptAlias /app /srv/App/App/wsgi.py WSGIPythonPath /srv/App <Directory /srv/App/App> <Files wsgi.py> Require all granted </Files> </Directory> settings.py STATIC_URL =...

How to gain Static Constructor's functionality in JAVA?

java,constructor,static,static-constructor
I am learning C# and JAVA I found Static Constructor in C# which is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced. For...

Access static method from static variable

python,python-2.7,static
There are plenty answers for how to access static variables from static methods (like this one, and that one, and the great info on the subject here), however I'm having trouble with the other direction: How can you use static methods to initialize static variables. E.g.: import os, platform class...

How do you link to site-wide static files in django 1.8?

css,django,static
Current structure: MySite |--MySite | |--static | |--MySite | |-- site_wide.css |--MyApp |--static |--MyApp |-- app_specific.js |-- app_specific.css settings.py: STATIC_URL = "/static/" STATICFILES_DIRS = ( os.path.join(BASE_DIR, "/MySite/static/"), ) With the following code I am able to successfully link to app_specific.js and app_specific.css, but am unable to link site_wide.css {% load...

How can I use a non-static (dynamic instance) object as return for a static method in Java? [closed]

java,static,return
I have searched through stackoverflow as well as a few other sites and sadly have not found this question asked, let alone answered. Maybe my approach is best attempted another way? I am new to Java; this should be a really easy answer I would think. The issue: I have...

Why can static member functions only be called at global scope if they have a return value?

c++,static,member-function
I found a peculiar thing: static member functions of a class/struct cannot be called a global scope, unless they have a return value. This program does not compile: struct test { static void dostuff() { std::cout << "dostuff was called." << std::endl; } }; test::dostuff(); int main() { return 0;...

Defining Macros that are equal to functions that return objects in C++

c++,static,macros,singleton
So I have the singleton pattern working the way I want to, I think the main problem is something with pointers and refrences. ("..." represents irrelevent code). Universe.h ... #define TheUniverse Universe::GetInstance (); ... public: static Universe& GetInstance (); ... private: static Universe* x_instance; ... Universe.cpp ... Universe* Universe::x_instance =...

access static member of template parent class

c++,templates,inheritance,static
#include<iostream> template<int n> class Parent { public: static const unsigned int n_parent = 5 + n; }; template<int n> class Son : public Parent<n> { public: static void foo(); static const unsigned int n_son = 8 + n; }; template<int n> void Son<n>::foo() { std::cout << "n_parent = " <<...

Returning a pointer which is a locally declared wchar_t

c,static,scope,return
I've read a lot of questions about returning pointers in C, but am still confused with the issue of scope. The following code works because of the call to malloc, and one possible output might end up being Wide string: StackOverflow. #include <stdlib.h> #include <string.h> #include <stdio.h> #include <wchar.h> static...

Adding subview to static UITableViewCell not working

ios,objective-c,uitableview,static,addsubview
I have a static UITableView. I'm trying to programmatically add a UISegmentedControl to the third cell. Here is the code: UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"First", @"Second"]]; segment.frame = CGRectMake(0, 0, 50, 30); UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1]]; [cell.contentView addSubview:segment]; When the code is called, the SegmentedControl isn't...

Difference between static and const variables [duplicate]

c#,variables,static,const,global
This question already has an answer here: What is the difference between Const and Static in C#? 5 answers what is the difference between "static" and "const" when it comes to declare global variables; namespace General { public static class Globals { public const double GMinimum = 1e-1; public...

Why cannot I transform the string “Feb 13 23:30:01 2014” to Date in R?

r,string,date,static
I am trying to convert strings like "Feb 13 23:28:34 2014" to Dates. But the "as.Date" function only produced "NA"s. How can I do it correctly? head(time) [1] "Feb 13 23:28:34 2014" "Feb 13 23:30:01 2014" "Feb 13 23:32:01 2014" [4] "Feb 13 23:35:48 2014" "Feb 13 23:43:45 2014" "Feb...

References - Why do the following two programs produce different output?

c++,reference,static,output
I recently read about references in C++. I am aware of basic properties of references but I am still not able to figure out why following two programs produce different output. #include<iostream> using namespace std; int &fun() { static int x = 10; return x; } int main() { fun()...

django how to include javascript in template

javascript,python,django,static,include
I'm starting a project and following the documentation I didn't succeed to include javascript. Here is my settings: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) STATIC_ROOT = '/static/' TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), ) So I have a static folder create in my project with a javascript file....

Static variables and memory consumption

objective-c,memory,static
With iOS, we always have to be concerned about memory consumption. I have a class that may have hundreds of instances, and I haven't been able to locate a discussion that indicates whether declaring a static dictionary inside an instance method means that all instances of that class will share...

Accessing non static members inside static method via passed pointer

c++,multithreading,static,this
Not the actual code, but a representation: I need to initiate a thread from one of my member functions and I do that this way: return_val = pthread_create(&myThread, NULL, myStaticMethod, (void*)(this)); i) I pass this as an argument because static methods do not allow non-static members to be accessed, and...

How to omit creating static Map for data caching?

java,caching,static,hashmap
I want to know if it is possible to omit creating cache with static Map instance. Here is snippet of my class: public class XpathEvaluator { private DocumentBuilder builder; private XPath path; private Document document; private static Map<String, List<String>> cachedXpaths = new HashMap<>(); private XpathEvaluator() throws ParserConfigurationException { DocumentBuilderFactory factory...

Why are exceptions in a static constructor wrapped in TypeInitializationException

c#,static
The exception from a static constructor is wrapped in a TypeInitializationException. Consider the example below using System; namespace ConsoleApp { class Program { static void Main(string[] args) { try { new MyClass(); } catch (Exception e) { Console.WriteLine(e.GetType().ToString()); } } public class MyClass { static MyClass() { throw new Exception();...

Why should we use a List of a particular type in Java

java,methods,arraylist,static,format
I am currently going through a lesson in Java, and this lesson covers passing an ArrayList object through a static method. In the first static method, you see that ArrayList only had to be declared as ArrayList, and a name for it. The first static method displays all of the...

How to compile fortran code to run without gfortran installed

osx,static,compilation,makefile,fortran
I have downloaded Bellhop, which is an underwater acoustic simulator written in Fortran. It can be found here with the Makefile. Question 1: I would like to know if it is possible to compile Fortran code, including everything needed, so a user without gfortran installed, can run it. I have...

Creating a static class with no instances

python,class,object,static
All of the tutorials I see online show how to create classes with __init__ constructor methods so one can declare objects of that type, or instances of that class. How do I create a class (static in Java) so that I can access all methods and attributes of that class...

Another way to program “static”: Is Code ok?

java,static
I need some advice about how to structure of my java applications. Personally I like to decide - like for example in python or C++ - if I program OO or not. For me, static is a way to do the same in Java. I read, most people say static...

Java import static method but not field

java,import,static
Take the following class for example: public final class ClassName { public static final void TEST() {} public static final Object TEST; } Now, from another file, I want to import static ClassName.TEST(), but not ClassName.TEST. How would I go about importing a method but not an identically named field,...

How to design a class that is constant after initialization and exists only once in my whole program

c++,design-patterns,static
I'm pretty sure that the following question already has a good answer somewhere else, but it's difficult to find since I do not know the "name" of my problem. I'm designing a class/object/"something" with the following properties: It is sort of a lookup table. It does not change after initialization....

Alternatives to mock an static method

java,junit,static,mocking,mockito
I am developing a desktop application, I want to test the method foo of MyClass and I have the following scenario: MyClass: import package.MainWindow; public class MyClass{ public int foo(){ //some logic // . . . boolean result = getResult(); if (result) { MainWindow.printInMain("Success"); return 1; } else { MainWindow.printInMain("Fail:...

Are static variables initialised from a file initialised only once

java,static
I am creating a class in Java to represent a String and a Color, called ColoredString. I wanted to be able to create one of these objects using a color name of any color recognized by the .Net framework. Such a list of colors is here: http://www.simplehtmlguide.com/colours.php. Since Java doesn't...

Display images on Django Template Site

python,django,image,static
I read a lot about including image files, but i still don't get it :( my models.py class Movie(models.Model): image_url = models.URLField(max_length=1024, blank=True, null=True) image_file = models.ImageField(upload_to='poster/', blank=True) my index.html {% load staticfiles %} <img src="{% static "{{movie.image_file}}" %}" /> The pictures are saved on harddisk /myapp/poster Thanks for helping....

C++11 MinGW 4.9.1 shared_ptr and const static class field result “Undefined reference”

c++,c++11,static,const,mingw32
#include <memory> class CItem { private: int m_inner; public: static const int CAP = 1; CItem(int temp) : m_inner(temp) {} }; typedef std::shared_ptr<CItem> TPItem; int main() { int tttt = CItem::CAP; CItem *temp = new CItem(CItem::CAP); TPItem temp2(temp); TPItem temp3 = std::make_shared<CItem>(tttt); TPItem temp4 = std::make_shared<CItem>(CItem::CAP); //On MinGW there error:...

static initialization of members of class of the same class in c++ [duplicate]

c++,static
This question already has an answer here: Static constant members in a class C++ 2 answers I dont know exactly how to call it in c++ but what i trying to do is to create General class that represent Color , with several members of that class are same...

Using variables / Static variables to 'name' values to aid readability

java,static,final
public class myObject extends someOtherObject(){ final int MAINBOX_X = 0; final int MAINBOX_Y = 1; final int BUTTON_X = 2; final int BUTTON_Y = 3; final int TEXT_X = 4; final int TEXT_Y = 5; public myObject(int x, int y){ super(); //'coordinates' is an array of pairs, x and y...

Java - Non-static method cannot be referenced from a static context

java,android,database,static
What I am trying to do should be simple: I am trying to use Android Studio to read an XML file and write the data to a database. A simplified version of my code goes like this: MainActivity.java: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) {...

Why using static classes to share global data is not a good practice? [closed]

c#,wpf,static,shared-data
I have heared that sharing data using static class properties is not a good practice. Although I haven't seen any one using this approach but I can't find out what are the drawbacks for such appraoch! To be more clear, Let's consider a WPF application composed of many UserControls that...

Calling base and derived static methods of a type variable

java,generics,static
I have the following example: class Ideone { public static void main (String[] args) throws java.lang.Exception { A<ConcreteErrorHandler> a = new A<ConcreteErrorHandler>(); a.m(); //Exception here! } public static class AbstractErrorHandler { public static void handle(){ throw new UnsupportedOperationException("Not implemented"); } } public static class ConcreteErrorHandler extends AbstractErrorHandler{ public static void...

return reference of static member variable c++

c++,reference,static
Is there any problem to return a reference of a static member variable? (Reference to avoid copy cost) Vector accepts 4 parameters(x,y,z,w); .h class MyClass { private: static const Vector POS; } .cpp const Vector MyClass::POS(100,300,0,0); const Vector& MyClass::GetVector() { return POS; } ...

using subclass's static variable in superclass

c++,variables,static,subclass
class Class1 { Class1() { Class2::counter++;} } class Class2: public Class1 { public: static int counter; } The above is an example of what I am trying to do. I am trying to use a static variable of a subclass in the superclass but that gives me a compiler error...

Strict Standards: Non-static method should not be called statically, assuming $this from incompatible context

php,static,standards,strict,non-static
This is a question specific to a custom wrote CMS we have taken over. We moved servers and the PHP version changed from 5.3.8 to 5.4.1. Since then we can't get the CMS to work and are getting this error: Strict Standards: Non-static method Vox_Model_Setting::getMapper() should not be called statically,...

django static folder name change

python,django,static
My django project is located at c:/django/project and static folder is at c:/django/project/app/static. I put bootstrap and jquery files to my template under link href="/static/ and src="/static/. But if i change name of folder with static files, they become unavailable. I tried to change settings.py settings and here is the...

How to call static method provided by protocol in Swift

ios,swift,static,protocols
How to access to static protocol method within a instance I have a list of Contact, the contact can be a FamilyContact that inherit from Contact and the GroupStatus protocol I want to call the static method from GroupStatus but in vain... Here is my code protocol GroupStatus { static...

Passing values from an array to child template in meteor

arrays,templates,meteor,static,nested
I've been grappling with the following problem: I have two templates: intervalsList intervalIcon I want intervalsList to populate with a list of intervalIcons. Each intervalIcon displays a number; there is an array of these numbers: [1, 5, 10, 15, 30, 45, 60] The intervalsList template iterates through this array, instantiating...

Passing integer value from MDI parent to child and back

c#,static,mdichild,mdiparent
I have a Windows Forms app with an MDI parent form (mdiBK) and a few child forms (form1 and form2 are the ones that matter). I would like to set an static int variable inside my parent form (mdiBK) and set it to '0'. On 'form1' there are 2 buttons...

How to fill HashMap object only once for program?

java,static,hashmap,instantiation
Given the following portion of my wider program: public class AnimalNames { private static String[] animalNames = {dog, cat, horse, cow, donkey, elephant}; private static String[] animalNameAbbreviations = {d, c, h, co, d, e}; public static HashMap<String, String> getAnimalNameTranslations() { HashMap<String, String> animalNameTranslations = new HashMap<String, String>(); for (int i...

Which is better programming practice - Unnecessary parameters or a static variable?

c#,parameters,constructor,static,xna
I am making a game in C# and XNA 4.0 and one of my classes requires its own texture. The class is currently being used like this: Class constructor: class Item : ItemBase //It uses a base class { public Item(Texture2D myTexture) : base(myTexure) { } } New instance: Texture2D...

how to increment value of string variable?

java,static
I have to increment the variable count and return as 001, 002...,099....,999 The update() returns the count value and reset() will resets the static variable The code i have used it. public class getCount { static String count="0"; //resets the value to 0 public static void reset() { // TODO...

Static class variables in Python — Lists & Objects [duplicate]

python,list,static,static-variables,class-variables
This question already has an answer here: How do I avoid having Python class data shared among instances? 6 answers I'm new to Python, with more of a Java background. I understand the concept of static class variables in Python, but it's come to my attention that lists and...

Perl: Static vs Package methods

perl,static,package
I need to create a package which will be used by other developers. What is the best way to implement static methods? For static (class) methods I must expect 1st parameter $class, and method must be called as a class method: My::Package->Sub1(); From the other hand I can write a...

Why do two programs have forward referencing errors while the third does not?

java,static,instance,forward
The following does not compile, giving an 'illegal forward reference' message: class StaticInitialisation { static { System.out.println("Test string is: " + testString); } private static String testString; public static void main(String args[]) { new StaticInitialisation(); } } However, the following does compile: class InstanceInitialisation1 { { System.out.println("Test string is: "...

Are memory addresses in assembly language statically allocated at once?

c,assembly,memory-management,static,allocation
I would like to write a C-program that allocates 20,000 memory lines with each line containing 8 bytes and are labeled in the range 2500 to 24999.. The program actually simulates a simple assembly language IDE. All the 20,000 memory lines may or may not be used at once. Suggest...

What is the meaning of “static” in parameters array types in C?

arrays,function,parameters,static,c99
I saw following little complicated function definition. void foo(double A[static 10]) { double B[10]; } Is it valid C & C++ code? Is it new syntax introduced by C99 or C++ standard? What is the purpose of it? When should I use it? What is the need for this?...

Is it possible to serve a static html page at the root of a django project?

python,html,django,static,pythonanywhere
I have a django app hosted on pyhtonanywhere. The app resides at username.pythonanywhere.com/MyApp. I would like to serve a static html page at username.pythonanywhere.com. Is this possible? Essentially it would serve as an index linking to /MyApp, /MyApp2, and other future apps. I can't seem to find any info on...

Laravel Eloquent: access method parameter within chunk Closure

php,laravel,static,scope,eloquent
I need to pass an anonymous function to a static method on an Eloquent model and have that static method call the closure within a chunk closure. The goal is code similar to the following: class MyModel extends Eloquent { // ... table stuff public static function doSomething (Closure $thing)...

Im referencing a constant class static variables, but when i do the values somehow change

c#,visual-studio-2013,reference,static
Here is my constant class that i reference from. Below that is the class that is trying to use the reference. Here is the error message im getting. The Type initializer for ConstantClass threw an exception ---> System.OverflowException: Value was either too large or too small for a Decimal. Any...

using i686-w64-mingw32-g++ for static libraries

static,jni
I have a JNI project, which I have to make work on Windows (I am working on Linux). This project actually depends on third-party library file which is static (archived i.e .a files). I am trying to create a JNI shared library file using i686-w64-mingw32-g++ and including -static followed by...