Create Object Array

I am trying to do a simple task that I thought would be very easy and quick to do but I have run into problems
I am trying to get the user to input a number and based on that number make a text field to become visible based on it. So if the user input 3 the first 3 textfields would become visible. I have 10 textfields and I don't need any error handling yet as I can do that later but this is my code:
var x=NumericField1.rawValue;
for(var i=0; i<=x; i++)
TextField1[i].presence="visible";
I think my problem is creating the object array as all I did was double clicked in the library to create the textfields and the names come up as TextField1 then in the grey shaded area right beside it is the number 0. The next one is called TextField1 with 1 greyed out beside it.
Can anyone help me out?
Thanks

SO IF YOU TRY IN JAVASCRIPT THIS WON'T WORK SO DO THIS IN "FORMCALC"
i=NUMIRICFIELD.RAWVALUE;
TextField1[i].presence="visible";
PLEASE DO THIS IN FORMCALC &FEEDBACK ME
[email protected]

Similar Messages

  • Creating  object array

    how to create an object array for the class ?
    which should be increment dynamically.

    i will have an separate class which has an JPanel
    with components for eg customclass .
    for that i need to create an object with array in the
    main class. which should be increment as the action
    performed.Is there a question you want to ask? You've already been given an answer to the one you asked, yet you replied with a nonsensical statement. There is no such thing as a "dynamic array" in Java. All arrays are of a fixed size. If you want a larger array you'll have to create a larger array and copy the contents of the old array to the new array. Alternatively you can use a List implementation such as ArrayList that can take care of that job for you.

  • Retrieved data from database assignd to object array

    Hi all,
    Im new to java. I creat class it has item_name,item_qty,item_price as properties.then i need to create object array type of that class.now i need to assign values to properties in each element of object array from the database.in my database has ITEM table it has data according to that properties of class.how i do this.please tel me .
    thanks in Advanced,

    Harsha_Lasith wrote:
    yes I knew connect to the database using JDBC.but i have not clear understand about instantiate an object of a class using a constructor.please give me some example for those.
    thanks in advance.If you don't know how to use constructors you really should not be trying to use the JDBC. Learn Java first.

  • Creating an array of objects of a class known ONLY at RUNTIME

    I have a method in a class which expects an array of objects of particular type (say A) as its only argument. I 'invoke' this method using reflection. I have the instances of the class A stored in a Vector. When I do 'toArray' on this vector, what I get back is an array of Objects and not an array of objects of A. I assign this array to the zeroth element of another Object array and pass that array as a second argument to the 'invoke' method. Of course, it throws an Exception saying - argument types mismatch. Because I am sending an array of Objects to a method expecting an array of objects of A. My problem is I don't know A until runtime. So I have to handle whatever I am getting back after doing 'toArray' on a vector as a Generic Object. I know there's another version of 'toArray' in the Vector class. But it's API documentation didn't help a lot.
    Can anybody please help me solve this problem? Any sort of hints/code snippet would be of great help.
    Does the above description makes any sense? If not, please let me know. I would try to illustrate it with a code sample.
    Thanks a lot in advance.

    Sorry, for the small typo. It is -
    clazz[] arr = (clazz [])java.lang.reflect.Array.newInstance(clazz, n);
    instead
    Thanks for the reply. I could do this. But I am
    getting a handle to the method to be 'invoke'd by
    looking at the types of the parameters its
    expecting(getParameterTypes). So I can't change it to
    accept an array of Generic Objects.
    I looked at the java.lang.reflect.Array class to do
    this. This is what I am trying to do-
    String variableName is an input coming into my
    program.
    n is the size of the array I'm trying to create.
    Class clazz = Class.forName(variableName);
    clazz[] arr = (clazz
    [])java.lang.reflect.newInstance(clazz, n);
    According to Reflection API, it should work, right?
    But compiler yells at me saying 'class clazz not
    found'.
    Any suggestions/hints/help?
    Thanks, again.

  • Formatted .data file, reading in and creating an array of objects from data

    Hi there, I have written a text file with the following format;
    List of random personal data: length 100
    1 : Atg : Age 27 : Income 70000
    2 : Dho : Age 57 : Income 110000
    3 : Lid : Age 40 : Income 460000
    4 : Wgeecnce : Age 43 : Income 370000
    and so on.
    These three pieces of data, Name,Age and Income were all generated randomly to be stored in an array of objects of class Person.
    Now what I must do is , read in this very file and re-create the array of objects that they were initially written from.
    I'm totally lost on how to go about doing this, I have only been learning java for the last month so anyone that can lend me a hand, that would be superb!
    Cheers!

    Looking at you other thread, you are able to create the code needed - so what's the problem?
    Here's an (not the only) approach:
    Create an array of the necessary length to hold the 3 variables, or, if you don't know the length of the file, create a class to contain the data. Then create an ArrayList to hold an instance of the class..
    Use the Scanner class to read and parse the file contents into the appropriate variables.
    Add each variable to either the array, or to an instance of the class and add that instance to the arraylist.

  • How to create an array of an object,

    Hi,
    Trying this in Oracle 10.3 studio, I have to use a web service, I have re-catalogued the web service succesfully,
    I am getting compilation error whenI try to create an array of a object,
    Services.PackageTrackingService.PackageTrackingItem[] pkgTrackingItem = new Services.PackageTrackingService.PackageTrackingItem[2];
    I am giving the array size as 2,
    The comilation error is showing as
    Multiple markers at this line
    - statement is expected
    - Expecting ';' but 'pkgTrackingItem' was found
    - expression is expected
    Is there any other way to create the array?
    Thanks in advance.
    -Sree

    Hi,
    Please declare the array in following manner.
    Services.PackageTrackingService.PackageTrackingItem[] pkgTrackingItem;
    Now you can insert the element into the array by pkgTrackingItem[0], pkgTrackingItem[1] etc.
    Bibhu

  • How to create an Array of Object

    Is this correct:
    Object[] anArray = new Object[5];
    Thanks.

    Your code will create an array of 5 null references to class Object. After that line you could code:anArray[0] = new Integer(5);- or -
    Object x = anArray[1];but if you code:anArray[3].DoSomething();and have not initialized anArray[3], you will get a NullPointerException.
    Doug

  • Adding user-created objects to an Array

    I would be grateful if anyone can help me. I have created the following class:
    import java.util.*;
    * Created on 08-Dec-2005
    * @author Hussein Patwa
    public class room {
        public String roomName;
    // String to hold the room name
        public static void main(String[] args) {
        String roomName;
        // Temp string to hold room name
        LinkedList objectqueue = new LinkedList();
        // Queue implementation to hold list of objects in room
        LinkedList stack = new LinkedList();
        // Stack implementation to hold objects held by user
    public void enterRoomName(String roomName) {
        // Method to allow entering of the room name
        this.roomName = roomName;
        // Assignment the room name to the roomName field
    public void viewRoomName() {
        // Method to allow the viewing of the room name
        System.out.println("This is the " + roomName + " ");
        // Print the room name
    }I also have a main class:
    import java.util.*;
    * Created on 08-Dec-2005
      * @author Hussein Patwa
    public class start extends room {
        public static void main(String[] args) {
      String gameName = "PatwaMaze";
      // Field to hold the game name
      room[] roomList = new room[6];
      // Create a new array to hold the rooms
    public void startGame() {
    roomList.add["Kitchen"];
    roomList.add["Parlour"]
    roomList.add["Lounge"]
    roomList.add["Stairs"]
    roomList.add["Chamber"]
    roomList.add["Study"]
    }I want to create an array of room objects, or would it be more correct to say object references, and then have their labels as the room name, which would be stored in that room's roonName field. So then I can iterate through the list, and print out each room's roomName field thus giving a list of the rooms. So (and I hope this is making sense), I need to add the rooms to the array, set each room's rromName field and then iterate through it. But I'm not sure of the syntax to add the room's name and the array index.
    BTW, I have done quite a bit of searching for this, as well as looked through several texts, so I am posting here because i'm not sure where to go next.
    Thanks.
    Hussein.

    Short answer: There's no add method. That woul be in a Collection.
    http://java.sun.com/docs/books/tutorial/collections/
    For an array, it's arr[0] = something;
    arr[1] = somethingElse;
    / / etc.

  • Create a unlimited object array.

    I need to be able to create an Object array of unlimited or extended size. I don't know how many of the objects I'm going to need when the program starts. I need the ability to alocate more space as needed. How can I do this. Please show a small example. Thanks.
    Matt S.

    Yes. You might need to cast the Object coming out of the List to whatever type you put in there. See the API docs for ArrayList. Depending on your needs you might want to use a Map or Set or Tree, look at the java.util classes that implement those interfaces and see what meets your needs.
    Lee

  • Creating an arrays of objects from a class

    I was wondering does any one know how to create an array of objects from a class?
    I am trying to create an array of objects of a class.
    class name ---> Class objectArray[100] = new Class;
    I cant seem to make a single class but i need to figure out how to create an array of objects.
    I can make a normal class with Class object = new Class

    There are four lines of code in your for-loop that actually do something:
    for(index = 0; index < rooms.length; index++) {
    /*1*/  assignWidth.setWidth(Double.parseDouble(in.readLine()));
    /*2*/  rooms[index] = assignWidth;
    /*3*/  assignLength.setWidth(Double.parseDouble(in.readLine());
    /*4*/  rooms[index] = assignLength;
    }1.) Sets the width of an object, that has been instantiated outside the loop.
    2.) assigns that object to the current position in the array
    3.) Sets the width of a second object that has been instantiated outside the loop
    4.) assigns that other object to the current position in the array
    btw.: I bet you meant "assignLength.setLength(Double.parseDouble(in.readLine());" in line 3 ;)
    Since each position in an array can only hold one value, the first assignment (line 2) is overwritten by the second assignment (line 4)
    When I said "construct a new room-object and assign it to rooms[index]" I meant something like this:
    for(index = 0; index < rooms.length; index++) {
        Room aNewRoom = new Room();
        aNewRoom.setWidth(Double.parseDouble(in.readLine()));
        aNewRoom.setLength(Double.parseDouble(in.readLine());
        rooms[index] = aNewRoom;
    }1.) Constructs a new Object in every iteration of the for-loop. (btw: I don't know what kind of objects you're using, so this needs most likely modification!!)
    2.) set the width of the newly created object
    3.) set the length of the newly created object
    4.) assign the newly created object to the current position in the array
    -T-
    btw. this would do the same:
    for(index = 0; index < rooms.length; index++) {
        rooms[index] = new Room();
        rooms[index].setWidth(Double.parseDouble(in.readLine()));
        rooms[index].setLength(Double.parseDouble(in.readLine());
    }but be sure you understand it. Your teacher most likely wants you to explain it ;)

  • Creating an array of objects sets them all to null?

    I am using the following code:
    public class PlayerTest {
        public static void main(String[] args) {
            Player[] p = new Player[1];
            System.out.println(p[0].getId());
    }and for the 'Player' object:
    public class Player {
        int id;
        String name;
        int prediction;
        int score;
        public Player() {
            this.name = "a";
            this.score = -1;
            this.id = genRanId();
            this.prediction = -1;
    ...and, when i try to execute the "PlayerTest" class, i get the error:
    Exception in thread "main" java.lang.NullPointerException
            at PlayerTest.main(PlayerTest.java:5)I think this is because when the array of player objects is created, they are all set to null, and the fields are not created. How do i get the program to initialise the fields in each player object of the array?
    Creating the array of Player objects doesnt seem to use the constructor for the player class like creating an indivdual one does for some reason, as if i create a single element, instead of an array of them, it works fine....
    Please help!

    Yes you are quite right they are null by default (that is nothing is assigned to the array of pointers you have created) you will have t initialise the array the array
            Player[] p = new Player[1];
            for(int i=0;i<p.length;i++)p[i] = new Player();
        //or you can do
       Player[] p = {new Player(),new Player()};(IMHO) Its pointless having an array like this with identical objects you are betteroff instantiating the Person class using a constructor that takes some initial parameters however it is up to you.
    Good luck
    Wiraj

  • Creating an array of objects

    Hey,
    I basically have two classes and am trying to create an array of one class in the sub class. My code keeps coming up with <identifier> expected on complie:
    Main Class
    import java.util.ArrayList;
    import java.io.*;
    * @author David Bainbridge
    * @Date 12/02/07
    public class Main {
             public ArrayList<City>ListOfCities;
    public static void main(String[] arguments) {
         Main.newcity();
         public Main() {
         ListOfCities = new ArrayList<City>(); //this creates an array which stores all instances of the cities.
         public static void newcity() {
              String Name = "Lincoln";
              String Lat = "10";
              String Long = "11";         
              ListOfCities.add(new City(Name, Lat, Long)); 
              Lincoln.displaycity();
    }City Class
      * The City class represents a City.
      * @author David Bainbridge
      * @Date 13/02/07
    public class City {
         private String Name;
         private String Latitude;
         private String Longitude;
          * Constructor for the City.
         public City(String cityName, String cityLat, String cityLong) {
              Name = cityName;
              Latitude = cityLat;
              Longitude = cityLong;          
          * Display the current City.
    public void displaycity() {
              System.out.println("Name: " + Name);
              System.out.println("Latitude: " + Latitude);
              System.out.println("Longitude: " + Longitude);
    }

    Thanks JJCoolB but neither worked!
    I have rejigged my code:
    import java.util.ArrayList;
    import java.io.*;
    * @author David Bainbridge
    * @Date 12/02/07
    public class Main {
             public static ArrayList<City>ListOfCities;
    public static void main(String[] arguments) {
         ListOfCities = new ArrayList<City>(); //this creates an array which stores all instances of the cities.
         Main.newcity();
         public static void newcity() {
              String Name = "Lincoln";
              String Lat = "10";
              String Long = "11";         
              ListOfCities.add(new City(Name, Lat, Long)); 
              Lincoln.displaycity();
    }I get two complie errors with it one says:
    public static ArrayList<City>ListOfCities; - <identifier> expected
    ListOfCities = new ArrayList<City>(); //this creates an array which stores all instances of the cities. - '(' or '[' expected.
    Thanks in advance for any help people!

  • Returning an Object Array

    I am unable to figure out the way in which I can return an object
    array from a cpp file to java. Is there any obvious error which you can spot in
    my CPP file?
    When I try to return a single object in the native function,
    it works fine but when I try to extend it and return an array of the object, it
    throws an error.
    Please find below the details
    h1. Java Class
    public class Flight {
    public String ID;
    public class InterfaceClass {
    private native Flight[] GetFlights();
    public static void main(String[] args)
    Flight[] objFlight = new
    InterfaceClass().GetFlights();
    System.+out+.println(objFlight[0].ID);
    static {
    System.+loadLibrary+("main");
    h1. CPP File
    JNIEXPORT jobjectArray JNICALL Java_InterfaceClass_GetFlights(JNIEnv env, jobject obj)
    //1. ACCESSING THE FLIGHT CLASS
    jclass cls_Flight = env->FindClass("LFlight;");
    //2. CONSTRUCTOR FOR FLIGHT CLASS
    jmethodID mid_Flight = env->GetMethodID(cls_Flight,"<init>", "()V");
    //3. CREATING AN OBJECT OF THE FLIGHT CLASS
    jobject objFlight = env->NewObject(cls_Flight, mid_Flight);
    //4. ACCESSING THE FLIGHT's "ID" FIELD
    jfieldID fid_ID = env->GetFieldID(cls_Flight, "ID","Ljava/lang/String;");
    //5. SETTING THE VALUE TO THE FLIGHT's "ID" FIELD
    env->SetObjectField(objFlight,fid_ID, env->NewStringUTF("ABC"));
    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");
    if(cls_Flight_Array == NULL)
    printf("Error-1");
    //7. CREATING A NEW FLIGHT ARRAY OF SIZE 1 jobjectArray arrFlightArray = env->NewObjectArray(1,cls_Flight_Array,NULL);
    if(arrFlightArray == NULL)
    printf("Error-2");
    //8. INSERTING A FLIGHT BJECT TO THE ARRAY
    env->SetObjectArrayElement(arrFlightArray,0,objFlight);
    return arrFlightArray;
    h1. Error
    # A fatal error has been detected by the Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION
    (0xc0000005) at pc=0x6d9068d8, pid=1804, tid=3836
    # JRE version: 6.0_18-b07
    # Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode, sharing
    windows-x86
    # Problematic frame:
    # V [jvm.dll+0x1068d8]
    # An error report file with more information is saved as:
    # C:\Users\Amrish\Workspace\JNI Test\bin\hs_err_pid1804.log
    # If you would like to submit a bug report, please visit:
    http://java.sun.com/webapps/bugreport/crash.jsp
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM

    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");The argument to NewObjectArray is the +element+ class of the array you're about to create, not the +array+ class itself.

  • How to create an array with Generic type?

    Hi,
    I need to create a typed array T[] from an object array Object[]. This is due to legacy code integration with older collections.
    The method signature is simple:public static <T> T[] toTypedArray(Object[] objects)I tried using multiple implementations and go over them in the debugger. None of them create a typed collection as far as I can tell. The type is always Object[].
    A simple implementation is just to cast the array and return, however this is not so safe.
    What is interesting is that if I create ArrayList<String>, the debugger shows the type of the array in the list as String[].
    If I create ArrayList<T>, the class contains Object[] and not T[].
    I also triedT[] array = (T[]) Array.newInstance(T[].class.getComponentType(), objects.length);And a few other combinations. All work at runtime, create multiple compilation warnings, and none actually creates T[] array at runtime.
    Maybe I am missing something, but Array.newInstace(...) is supposed to create a typed array, and I cannot see any clean way to pass Class<T> into it.T[].class.getComponentType()Returns something based on object and not on T, and T.class is not possible.
    So is there anything really wrong here, or should I simply cast the array and live with the warnings?
    Any help appreciated!

    Ok. May be you could keep information about generic type in the your class:
    public class Util {
        public static <T> T[] toTypedArray(Class<T> cls, Object[] objects){
            int size = objects.length;
            T[] t = (T[]) java.lang.reflect.Array.newInstance(cls, size);
            System.arraycopy(objects, 0, t, 0, size);
            return t;
    public class Sample<T> {
        Class<T> cls;
        T[] array;
        public Sample(Class<T> cls) {
            this.cls = cls;
        public void setArray(Object[] objects){
            array = Util.toTypedArray(cls, objects);
        public T[] getArray(){
            return array;
        public static void main(String[] args) {
            Object[] objects = new Object[] { new LinkedList(), new ArrayList()};
            Sample<List> myClass = new  Sample<List>(List.class);
            myClass.setArray(objects);
            for(List elem: myClass.getArray()){
                System.out.println(elem.getClass().getName());
    }

  • Object array - how to add items?

    Hello!
    I have little problem, how to add item to array, to get something like this:
    Object[][] someObject = {
    {"1", "2"},
    {"4","5"}
    };From this:
    Object[][] someObject = {
    {"1", "2"}
    };? Thanks in advance!

    Once you allocate an array like that, you can't
    resize it.
    Object[][] someObject = {
    {"1", "2"}
    };creates an array with size [1][2]. You can't makeit
    any larger. You can create a new Object[][]
    with the new size, copy the elements into the new
    array, then add your new objects in the newposition.
    or even better use arraylistExcept that he's using this for a JTable, so the best he could do is a Vector. Yuck. :)

Maybe you are looking for

  • Which table we will find paid invoices

    Hi Folks, Can you please let me know , what is the tables and fileds contains paid invoices and deuplicate invoice with same invoice number. Thanks in adavance. regards Vishal

  • How can we write to directly to ethernet

    Hi... How can one read/write directly from/to ethernet. Our requirment is the following. We want to put the PPP packets directly to ethernet so that solaris ppp/ip/tcp can read it and can put to the tftp application. thanks Sarika

  • Bluetooth issues - cannot 'discover' other apple products!

    Im not sure if this is an issue or if Im doing something wrong because I cant find any info online about other ppl facing the same problem. Basically, when I switch the Bluetooth ON, my iphone and my ipad both cannot find each other or my MacBook Pro

  • WLI 2.1 installation problem

    Hi all, I have downloaded WebLogic Integration 2.1. According to the guide, I have installed WebLogic App Server 6.1 sp1 and then try to install WLI2.1. But an error "WebLogic Server 6.1 SP1 is a prerequisite for this installation. You do not seem to

  • Why isn't the new itunes able to be downloaded to windows xp

    it says that the new itunes has not been approved by windows testing logo? how can i download the new itunes