Instance of the static class.

I'm working on my database helper class. My need is to have a single instance of this class in the application. In the development of cascades of BB that we create an object of the class to access its functions in another class and qml, we must have the class as an attached object so that we can call the method it contains the ID said. But I don't want my instance of the database class to be created every time I want to call a helper class database work, but only the first time when the user connects to the application. I want this forum to be available throughout the application. Please do advice if you have solved this problem successfully. Any bit of code is also welcome. Thanks in advance.

1. no idea. try to create a new class, it works there?
2. I use setProperty with the instance method

Tags: BlackBerry Developers

Similar Questions

  • How to access the static class variable calendar / singleton?

    How can I access a timeline of a static class variable / singleton?

    You can pass any object to display list to your class when instantiating it.  all objects in the display list has a placement property that allows access to the stage and them you can use the correct path/name to your variable.

  • Best way to insert data into instances of the custom class

    Hello.

    I have created a custom class (mySuperClass) in an .as file, defined constructor methods, properties, and the get/set. Now in the main .fla I must declare a large number of instances of this class and complete each property. The 'proper' method, I guess, would be to:

    var super1:mySuperClass = new SuperClass();
    super1.setProperty1 ( value1_1);
    super1.setProperty2 ( value1_2);
    ...
    super1.setPropertyN ( value1_N);

    ...
    var superM:mySuperClass = new SuperClass();
    superM.setProperty1 ( valueM_1);
    ...
    superM.setProperty1 ( valueM_N);

    However, with large quantities of variables and information that share the same basic characteristics, I feel always attempted to do through a cycle of dethrone. In that case, I'd probably build tables with the properties to complete.

    So I want to know is how would you guys do it? Are there other ways to do it?

    Thanks in advance.

    Well, the example is based on an object that has a datamodel and which can be any object of course. Now, assuming that the data come Let's say an xml file, I would use a function as the code to generate a collection of objects.
    Edit: so the StoreItem instances are created on the fly and saved in the collection

  • Reassign the variable to an empty instance of the class class

    When I declare a class variable

    private var myVar:MyClass = new MyClass();

    It creates a new instance of this class, which will trace as [object MyClass].


    However, as soon as I assign to something

    myVar = thisOtherVar;

    It will trace now as [Object thisOtherVar].

    I need to get back to where it is just an instance of the empty class "empty", if it has any sense at all.

    How can I do this? Thank you!

    I think you're overloading the things how I would do is to have two classes: letter class and (for lack of a better term) of Word, both extends Sprite.

    Class letter distributes the mouse (drag start) press events and on the release of mouse (stop drag).

    Word class look over the events. On the event of publication (drop), if the letter fell into one of his empty housing fills the array of letters. On the Press Conference (pick up = start drag) if the letter was in one of the slots, lift the range of letters.

    When you press the button 'Search' you use the table of letters in the word class to see if it forms a Word. Simple

  • Creating instances of the class customized for XML nodes

    Hi guys,.

    I'm trying to load an external XML document in my application and create an instance of a custom class for each node in the XML file based on the value of some of their elements. Instances created later will end by in a DataGrid by the way. The problem I have is there seems to be several ways to make small parts of it and I have no idea how do them all gel. Initially, I use HTTPService to load the XML file, but I've seen people just use a XML object. Then, after that, I put the XML loaded to an ArrayCollection collection initially, but others used XMLList or XMLListCollection. I have no idea of what is the best way to do it.

    Finally, when I created all of these instances by looping through XML and their creation how I'll make them bindable to the DataGrid? I guess I'll have to group together them somehow...

    Any help would be greatly appreciated. Thank you

    Create a class customized for your 'point' of dataGrid dataProvider objects
    * Use HttpService to get the XML code.
    * use an e4x expression for the child nodes of the xml in an XMLList: myXML.children () or myXML.myNodes;
    * use a for loop on the XMLList
    * inside of the loop, create a new instance of the custom class
    * Of the [i] myXMLList, obtain all necessary attribute values and assign them to the appropriate properties in the instance of the custom class.
    * always inside the loop, use myArrayCollection.addItem (mycustomClass) to add the element to the collection of the dataProvider ArrayCollection.

    Tracy

  • Passing an object of the UiApplication class reference

    Hi all

    I am very new to the development of BB and have struggled for hours on something that I think should be very simple. What I have, this is the main class that extends UiApplication and a second class that implements Runnable. From a method in the UiApplication class, I create an instance of the Runnable class. After that, I call a method to start from this class and pass an object originally from the UiApplication class reference - so that I can call a method, once completed the processing of the Runnable class.

    The problem I have, is that once past the object through a call to method reference, the reference instantly cancels and causes a NullPointer exception when trying to call a method in the original class. The structure is as below, but with all the surrounding code subscribed:

    public class MainApp extends UiApplication {
    
        MainApp _MainApp;
        OtherClass _OtherClass;
    
        public static void main(String[] args) {
        MainApp _MainApp = new MainApp();
        _MainApp.enterEventDispatcher();
        }
    
        private void createOtherClass() {
            _OtherClass = new OtherClass();
            _OtherClass.someMethod(_MainApp);
        }
    
        public void response() {
            // code here
        }
    }
    
    public class OtherClass implements Runnable {
    
        MainApp _MainApp;
    
        public void someMethod(MainApp MainAppRef) {
            _MainApp = MainAppRef;
            // _MainApp object reference is null here
    
            new Thread(this).run();
        }
    
        public void run() {
            // stuff here
            // once done, call a different method
            sendDetailsBack();
        }
    
        public void sendDetailsBack() {
            _MainApp.response(); // causes a NullPointerException
        }
    }
    

    I rewrote this to only show the code at the source of the problem. I don't quite understand why the object reference is not passed correctly - I have tried many other ways to call back to the UiApplication function, including static calls.

    Any help on how I do it is very appreciated!

    Will be

    I suspect that your problem is here:

    MainApp _MainApp = new MainApp();

    I think you meant just

    _MainApp = new MainApp();

  • Static class functions: PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]

    Any ideas why this would generate an internal error - referring to a static class function in the constructor of this class parameter signature?

    Test case (on 11.2.0.2) as follows:
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4  
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7  
      8          constructor function TMyObject(
      9                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
     10          )return self as result
     11  );
     12  /
    
    Type created.
    
    SQL> 
    SQL> create or replace type body TMyObject is
      2  
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7  
      8          static function DefaultName return varchar2 is
      9          begin
     10                  return( 'foo' );
     11          end;
     12  
     13          constructor function TMyObject(
     14                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
     15          )return self as result is
     16          begin
     17                  self.id := objId;
     18                  self.name := objName;
     19                  return;
     20          end;
     21  
     22  end;
     23  /
    
    Type body created.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    declare
    *
    ERROR at line 1:
    ORA-06550: line 0, column 0:
    PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]
    If static class functions are removed from the manufacturer and applied to the place inside the body of the constructor, it works without error. Similarly, you can call the constructor with the functions of the static class as parameters, without causing an internal error.
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4  
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7  
      8          constructor function TMyObject(
      9                  objID integer default null, objName varchar2 default null
     10          )return self as result
     11  );
     12  /
    
    Type created.
    
    SQL> 
    SQL> create or replace type body TMyObject is
      2  
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7  
      8          static function DefaultName return varchar2 is
      9          begin
     10                  return( 'foo' );
     11          end;
     12  
     13          constructor function TMyObject(
     14                  objID integer default null, objName varchar2 default null
     15          )return self as result is
     16          begin
     17                  self.id := nvl( objId, TMyObject.DefaultID() );
     18                  self.name := nvl( objName, TMyObject.DefaultName() );
     19                  return;
     20          end;
     21  
     22  end;
     23  /
    
    Type body created.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject(
      5                          objID => TMyObject.DefaultID(),
      6                          objName => TMyObject.DefaultName()
      7                  );
      8  end;
      9  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    Had a look on support.oracle.com and turned toward the top of the specific remarks concerning the use of the static class functions in the signature of the constructor parameter. Known issue? Any other solution in addition to the above?

    Hello

    There is a bug: ""Bug 8470406: CREATING an OBJECT INSTANCE FAILS WITH the ERROR PLS-00801 IN 11 GR 1 material ", it shows the behavior in 11 g but not to the point 10.2." It gives exactly the symptoms you see also, move to the body and it works. But he gave no solution/patch.

    Herald tiomela
    http://htendam.WordPress.com

  • Static Classes & events

    Can it only an instance of a class expedition event, or the static class can too?

    We have static class MyManager:

    package managers

    {

    Import mx.rpc.CallResponder;

    import of services. MyDataService;

    Import valueObjects.MyValueObject;

    Public NotInheritable class MyManager

    {

    public static var updateDataResult:CallResponder = new CallResponder();

    private static var myDataService:MyDataService = new MyDataService ();

    private static var myValueObject:MyValueObject = new MyValueObject();

    Public Shared function updateMyDataService (): void {}

    updateDataResult.token = myDataService.update (myValueObject);

    }

    }

    }

    And the other class which calls:

    import managers. MyManager;

    MyManager.updateMyDataService ();

    MyManager.updateDataResult.addEventListener (ResultEvent.RESULT, resultReceived);

    and this event listener does not work.

    Hi Banditizm,

    Yes you can even send your static callResponders events, but I think that the difficulty you might face you cannot capture or listen to events sent.

    You can do something, you can send these events w.r.t. systemManager and also listen to these WRT events there.

    I mean your shipment to help call the event as below...

    systemManager.dispatchEvent (new Event ("dataLoadComplete"));

    And you can listen in your mxml or as .as file below...

    systemManager.addEventListener ("dataLoadComplete", onDataLoadComplete);

    Thank you

    Jean Claude

  • Use of the static keyword in this context?

    Hi all

    I have an application that has a class I want that all the other classes to access them. I'm not sure is how implement it correctly or it even happen. For example, consider the following:

    Main class
    public class Main {
    
        public static void main(String[] args) {
            new Main();
        }
    
        static SecondClass secondClass = new SecondClass();
    
        public Main() {
            
        }
    
    }
    Second class
    public class SecondClass {
    
        public void method() {
            System.out.println("Method in Second Class");
        }
    }
    Third class
    public class ThirdClass {
    
        public void doSomething() {
            //is this appropriate?
            Main.secondClass.method();
        }
    }
    Now I know that I could just pass an instance of the second class to all classes that need to use the second class, but I thought it would be easier to declare the second static class instance so that I could do the following to access easily given that I only ever need one instance of the class :
    Main.secondClass.method();
    So my question is, this approach would be appropriate or it is badly perceived to access a class in this way?
    Thank you. :)

    I know that my problem would be solved if all of these classes were in a class

    No, your project is too important so a class... it has too many different types of objects.

    Neptune, I see that your project suffers from the poor class design. It seems obvious to me that you DON'T know what must do your application, you know what it should look like, you know that you listen to the clicks of a mouse, you know you need thumbnails etc etc. But none of this will work if the data is not organized properly - and that will not happen if you do not know how each each object fits.

    You develop this project to the rear. Start with data. It is. What are the data? How should be organized? What data should go to what class? etc. In addition, you must name your classes with intuitive names.

    Since your project is essentially a Photo Viewer, I sggest you name your main class just that...

    public class PhotoPreviewer
    {
      Album[] albums;
    }
    

    ... Notice the preview generator will now be able to access an array of objects from the Album. Now for the class from the Album...

    public class Album
    {
      String albumName;
      Photo albumPhoto;
      Photo[] photos;
    }
    

    ... see how each album has now a name and a single object of Photo to represent it in the previewer? It also contains an array of Photo objects, which we will see now.

    public class Photo
    {
      URL url;
      BufferedImage image;
      BufferedImage thumbnail;
    }
    

    See how each picture maintains the URL, an image, and it's own miniature?

    Now you can see what the data is and how the photos and Ablums of fit together to make the whole of the PhotoPreviewer project.

    But with all these classes separated I'm not sure how to communicate properly.

    Just add the combination of methods of accessor (GETTER and SETTER) as well as the methods of transmission as I described above.

    Neptune, you see that you need start your projects based on the data it processes? Do not start a project of the graphic aspect and Auditors, managers and the buttons of the things... Start your projects with the data, and how these data fit. Once you get the data goes, THEN add graphics, pretty icons and a graphical interface.

  • Cannot use casting "to more specific class ' function to the parent class of child class

    Hello

    I am using OOP for my request for data acquisition. I have different e/s analog and digital materials. I create a superclass named DAQ.lvclass. This class has four childs: analog in out analog, digital, and Digital Out. I am trying to invoke screws of the child of the parent class's class. For that I am throwing the class parent her child to aid "to a more specific class' function. But I get the below error.

    Error 1448 occurred at the more class specific in DAQ.lvclassMain.vi AQ

    Possible reasons:

    LabVIEW: Bad type cast. LabVIEW does not deal with the run-time value of this class of LabVIEW as an instance of the given class of LabVIEW.

    How can I handle these cases where I have to call child VI of the parent member?

    I have attached two screws 1 snapshot. Main DAQ: it's the class main VI parent who manages all functions. 2. read the analog inputs: this VI trying to set the parent class for its class of the child and child vi reads value of data acquisition task. I get the second error off VI.

    Kindly help.

    Honestly, I have NO idea on what you want to do.

    Inheritance of classes in EACH OOD (object-oriented design) requires to define common ground as the parent class. Children can add things like properties and methods.

    If you set children who have no points in common, you have made a mistake.

    If all children have too many different specific methods, your OOD is absent.

    Example:

    Parent defines the method A.

    1 child adds the B method.

    Child 2 adds method C.

    But method B will not be usable on 2 children while method C will not work with 1 child.

    It is an approach that you want to prevent. In any programming language oriented OBJECT. This adds unnecessary complexity leading to difficult to maintain the code, and it is prone to errors.

    However, if you're going to do, "to more specific class ' is the correct type cast. But your screenshots and error messages, it is obvious that refine you a particular child's casting only. You must extend the code to check the real child, specifically expressed and call the method. That being said, your code increases the complexity you want to add a bunch of case of structures which essentially nihilates all THE BENEFITS of the use of OOP.

    I'm sorry to say that.

    Norbert

  • Error 1448. LVOOP: Referring to objects of the child class

    Hi all.

    In a project using LVOOP, I defined a class parent with several attributes. Of this class, there are three classes of children who inherit the attributes of the parent class and also have their own.

    Imagine that I instantiated an object belonging to the parent class and initialize its attributes. So I want this object even belong to a class of the child in particular, and refer to its attributes in the class of the child, of course, keep the values of the parent class. How can I do?

    I tried to use "in a more specific class" tool but I get the following text: "error 1448: bad type cast." LabVIEW does not deal with the run-time value of this class of LabVIEW as an instance of the given class of LabVIEW. »

    Exactly the same problem is committed and solved here http://lavag.org/topic/7473-lvoop-class-variable-as-child/, but because the links are temporarily disabled I can't download and understand the code example, which shows what it says there.

    Thank you very much
    Francisco.

    Hi Francisco,.

    Take a look at this thread: http://forums.ni.com/ni/board/message?board.id=170&message.id=362388&requireLogin=False

    Christian

  • Instance create the function

    Jyn

    I need some help with a game that I do. I have a list of instances, and I want to make a function that will create another symbol, similar to that was just clicked. The problem is that I don't know how to create the new instance... In my library, they are like 'next' link + name of the instance. Thank you for your help ^^,

    square_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    circle_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    ...

    triangle_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    function Create(event:MouseEvent):void

    {

    var name: String = "next" + event.target.name;

    var temp: Name = Name();

    addChild (temp);

    lines of code

    removeChild (temp);

    }

    Here's the right way to dynamically call an instance of the current class.

    var ClassRef: Class = Class (getDefinitionByName ("className");
    var classInstance: * = new ClassRef();
    addChild (classInstance);

    In your case, 'className' would be your "next" + event.target.name;

    and you can use event.currentTarget.name to be safer.  If your objects contain other objects in their midst, 'target' can point to them instead.  "currentTarget" will always point to the object with the listener who are entrusted to him.

  • Unusual use of the static getInstance factory class definition interface

    This question is prompted by a recent new to Java forum question asking about the differences between Interfaces and abstract classes. Of course, one of the standard things mentioned is that interfaces can't actually implement a method.

    One of my former clients, the 500 group, using interfaces as class factories. The interface defines a static class of the pubis with a static method public, getInstance, who is called to generate instances of a class that implements the interface.

    This architecture was very object oriented, made good use of polymorphism and worked very well. But I have not seen this used anywhere architecture elsewhere, and it seemed a bit convoluted.

    Here's a version of 'Nick' of the model of the base interface and use
    -- interface that defines public static factory class and getInstance method
    public interface abc {
        public static class FactoryClass
        {
            public static abc getInstance ()
            {
                return (abc) FactoryGenerator(new abcImpl(), abc.class);
            }
        }
    }
    
    -- call of interface factory to create an instance
    abc myABC = abc.Factory.getInstance();
    1. each major functional area ('abc' in the above) has its own factory of interface
    2. each major functional area has its own implementation of this interface class
    3. There is a generator (FactoryGenerator) that uses the interface class ("abc.class") to determine the implementation to instantiate classes and return. The generator class can be configured at startup to control the actual class of return for a given interface.

    I should mention that the people who designed this whole architecture were not novices. They wrote very sophisticated multi-threaded code that rarely had problems, was high performance and was easy to extend to add new features (interfaces and classes of application) - pretty much plug-n-play with little, if any, side effects affecting existing modules.

    It is a process of best practices of factory design classes and methods? Please provide feedback about the use of an architecture like that.

    The way he explained to me at the time is that the interface uses standard naming conventions and acts as a template to make it easy to clone new modules: just change 'abc' to 'def' in three places and write a new class of "defImpl" which extends the interface and the new interface and the class can simply 'plug in' to the framework.

    There are in your pseudo code code in the interface to build a new abcImpl(). This deployment of a new plant means a change of this interface. If this is what is meant, it is poor. See java.util.ServiceLoader for an example of the right way to do it, with the implementation classes named in an external file.

    The generator class might use the information, if provided, to provide a new version of the class which would extend this default class.

    I hope so, but who is not exposed by your pseudocode.

    I never saw any 'Java' pattern that looks like this or any model where a contained interface a class.

    There are several examples in the JDK. Unfortunately I can't think of them right now. ;-)

    It seemed really complicated for me

    Me too.

    and it looks like the "versioning" aspect could be accomplished in a much simpler way.

    Indeed, he can see java.util.ServiceLoader.

  • How to access the BitmapData instance on the class that extends the charger?

    Hello. I use Flash CS6 to create an AIR application that loads an image from the computer, and then a pixel counts using its bitmap data.

    MyImg is a class that represents the loaded image.

    package com.utils {}

    import flash.display.Loader;

    SerializableAttribute public class extends {charger MyImg

    public void MyImg (): void {}

    }

    }

    }

    In my main class I manage the selection of files and loading.

    private var _myImage:MyImg = new MyImg();

    private var _file:FileReference;

    private var _fileTypes:FileFilter = new FileFilter ("Imagens: (*.jpeg, *.jpg, *.gif, *.png)", "*.jpeg;") *.jpg; *.gif; *.png");

    When the user clicks on a "load image" button on the stage, it calls loadMyImg().

    public void loadMyImg($e:MouseEvent):void {}

    chooseFile();

    }

    The user then selects the file he wants to do.

    private function chooseFile (): void {}

    Inasmuch = new FileReference();

    _File.addEventListener (Event.SELECT, fileSelected);

    _File.browse ([_fileTypes]);

    }

    Once you have selected the file, it is loaded as a byte array.

    private void fileSelected($e:Event):void {}

    _File.removeEventListener (Event.SELECT, fileSelected);

    _File.addEventListener (Event.COMPLETE, fileLoaded);

    _File.load ();

    }

    When it finishes loading it loads the byte array in _myImage.

    private void fileLoaded($e:Event):void {}

    _File.removeEventListener (Event.COMPLETE, fileLoaded);

    _myImage.contentLoaderInfo.addEventListener (Event.COMPLETE, dataReady);

    _myImage.loadBytes (_File.Data);

    }

    Once it's done I try to use the _myImage BitmapData, but cannot...

    private void dataReady($e:Event):void {}

    $e.target.loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, dataReady);

    trace ($e.target + $e.target.content + $e.target.content.name + $e.target.content.bitmapData); Returns [object LoaderInfo] [object Bitmap] instance 155 [BitmapData object]

    trace (_myImage + _myImage.content + _myImage.content.name + _myImage.contentLoaderInfo + _myImage.contentLoaderInfo.content.name); instance of [object LoaderInfo] 155 155 instance [object Bitmap] returns [object MyImg]

    trace (_myImage.content.bitmapData) //compiler error: 1119 of bitmapData property possibly access not defined through a reference with static type flash.flashDisplay:DisplayObject.

    error //same trace (_myImage.contentLoaderInfo.content.bitmapData)

    }

    I don't understand what I'm doing wrong. Instances have the same name so that they are identical. They both trace as bitmaps, yet when I didn't access it from the event I do not get the bitmapData. Can someone tell me what I am doing wrong? I need to use the bitmapData of the classroom MyImg. I guess I could create a BitmapData variable in the class and give it the value of $e.target.content.bitmapData, but I still want to know why it can't be simpler.

    Thank you!

    Cast _myImage.content as bitmap:

    Bitmap (_myImage.Content)

  • To access the upper class instance variables

    Hello

    See the code provided below. If home * variable 'i' is not set to 4, the output will be 3, if it is set, it will be 4.
    My question is... Well, I don't know exactly, there would be a lot. All this is strange to me.
    (For example, it seems that for the super class constructor runs when I access an instance of her variable).
    Could someone explain this topic or maybe help me to direct to an article?
    public class TryThis {
        
        public static void main (String args[]){
    
             Child c = new Child();
             c.seeSuper();   
        }
    }
    
    public class Parent {
    
         int i;
         
         Parent(){
              i = 3;
         }
    }
    
    public class Child extends Parent{
    
         Child(){
              //i = 4;  //***
         }
         
         public void seeSuper(){
              System.out.println(super.i);
         }
                        
    }
    Note: Parent could also simply look like this:
    public class Parent {
         int i = 3;
    }

    I see now that it is wrong to use the word 'object '.

    No, it isn't.

    they are there for the child to use, object

    That's where you're going wrong. Don't think about "the parent" and "child object. There is only one object, and it is mentioned by "this". You should think about members of the base or the classes and members of the (current) derived class. They are all members of the 'object', but the members of the base class can be hidden by the current members of class with the same name. That's all. Nothing too special about it.

    but they aren't the fields of it.

    Yes they are, but if they are hidden by local declarations that they are not visible to 'this', only to 'super '.

Maybe you are looking for