static-methods

java null pointer exception with static array

独自空忆成欢 提交于 2019-12-11 05:02:23
问题 I got a null pointer exception when accessing a static array from a static member method. The exception is thrown when i call setData(x, y, z) from a thread. When I debugged it I found out data[0] is null when i try to write to it. I just don't understand how it can be null public class dataContainer { private static final short nrOfDataElements = ids.total_ids; private static regularDataElement[] data = new regularDataElement[nrOfDataElements]; public static synchronized void getData(final

Static method for XMLLoader class… how to return XML data after Event.COMPLETE function?

丶灬走出姿态 提交于 2019-12-11 04:58:09
问题 I am attempting to build a generic XMLLoader class with a static LOAD method, with the intent to use it as follows... private var _data:XML = XMLLoader.LOAD("path/to/xml_file.xml"); Then I could use it in any client and go-to-town with e4x. The general problem I am having is with the URLLoader's COMPLETE event, which necessarily calls a different function to set the XML data. This is preventing me from being able to return the XML from the LOAD method, since the data is being set outside that

Accessing non-static combbox property in the static method

流过昼夜 提交于 2019-12-11 04:54:57
问题 I have one combobox on the window form and I have one method which is declared with static like private static DataTable ParseTable(HtmlNode table) Now I want to use combobox in that method for using combobox property but I can not access any property of combobox or combobox itself.If I made the combobox declaration as static then it can be accessed in that static method.But any alternative way to access combbox property in that static method because I don't want to make combobox declaration

Explicitly call static constructor in base static constructor

不羁的心 提交于 2019-12-11 03:08:45
问题 This one's a little weird/complex and more just curiosity than anything. I was looking for a way to make sure static calls from a base class could safely use static information set up in a derived class. I then noticed that C# allows me to call the derived class static constructor in the base class static constructor. My question: Is is safe to call the derived class static constructor in the base class static constructor Here is some sample code: public abstract class Enumeration<TEnum,

Combined static member and method

最后都变了- 提交于 2019-12-11 02:59:53
问题 Consider a class with a static member and a static method to set the value of the member (following is based on @JamesKanze 's example ): class A_EXPORT InA { public: static FILE* ourDest; static void setDest( FILE& dest ); }; An article (on logging) in Dr. Dobbs would suggest that the static member and static method be combined as follows: // in header file class A_EXPORT InA { public: static FILE*& theDest(); // a static member that is a static method too! }; // in cpp file FILE*& InA:

Android Studio 1.2.2 Static Import Completion

时光怂恿深爱的人放手 提交于 2019-12-11 02:43:27
问题 I'm trying to run Suger ORM v1.4 sample in Android Studio 1.2.2 that uses static imports! Example: import static com.orm.SugarRecord.save; What I have tried: 1>First I have tried to solve by this Settings -> Code Style -> Java -> Imports In the middle of the pane is the "Packages to Use Import with '*'" table. You can add an entry here of a fully-qualified class name, and tick the static box; now all static methods in this class will be available for auto-completion. Ref: IntelliJ Static

PHP: When would you need the self:: keyword?

让人想犯罪 __ 提交于 2019-12-11 01:37:45
问题 I just asked this question about the self:: keyword and didn't realize the static:: keyword existed. It seems to me that you could use ClassName:: if you needed to reference a particular class explicitly, and otherwise you'd want self:: to mean the class that called the method. I'm trying to think of an example of when you would need self:: where you couldn't just use ClassName:: . Could you replace all occurrences of self:: with ClassName:: , where ClassName is the name of the class

Class instance as static attribute

a 夏天 提交于 2019-12-10 21:08:34
问题 Python 3 doesn't allow you to reference a class inside its body (except in methods): class A: static_attribute = A() def __init__(self): ... This raises a NameError in the second line because 'A' is not defined . Alternatives I have quickly found one workaround: class A: @property @classmethod def static_property(cls): return A() def __init__(self): ... Although this isn't exactly the same since it returns a different instance every time (you could prevent this by saving the instance to a

Passing static method as argument, no address-of operator required?

 ̄綄美尐妖づ 提交于 2019-12-10 19:07:13
问题 class ThreadWorker { public: ThreadWorker(void); virtual ~ThreadWorker(void); static void DoSomething(); }; int main() { boost::thread thread1(ThreadWorker::DoSomething); boost::thread thread2(ThreadWorker::DoSomething); boost::thread thread3(&ThreadWorker::DoSomething); } I'm playing around with Boost.Thread and I notice it doesn't seem to matter whether I use the address of operator (&) or not when passing a static member function as an argument. Does it not matter? And if not, why? Is one

Static variables and methods

放肆的年华 提交于 2019-12-10 18:39:25
问题 I ran across a class that was set up like this: public class MyClass { private static boolean started = false; private MyClass(){ } public static void doSomething(){ if(started){ return; } started = true; //code below that is only supposed to run //run if not started } } My understanding with static methods is that you should not use class variables in them unless they are constant, and do not change. Instead you should use parameters. My question is why is this not breaking when called