Question about nulling array elements

Hi guys. What I want to do is null some array elements. Like:          
     for (int i = 1; i <= arrayA; i++) {
     for (int j = 1; j <= arrayB; j++) {
     Object o = class.getElem(i,j);
o = null;
Why this doesnt work? Thanks in advance

You are only setting your local reference "o" to null. Whatever is in the class at index "i , j" is not affected--o is just a copy of the reference (not a copy of the object). You'll need something like:
class.setElemNull(i,j);Where that method would set the appropriate value in your class to null.

Similar Messages

  • A basic question/problem with array element as undefined

    Hello everybody,
    thank you for looking at my problem. I'm very new to scripting and javaScript and I've encountered a strange problem. I'm always trying to solve all my problem myself, with documentation (it help to learn) or in the last instance with help of google. But in this case I am stuck. I'm sure its something very simple and elementary.
    Here I have a code which simply loads a text file (txt), loads the content of the file in to a "var content". This text file contents a font family name, each name on a separate line, like:
    Albertus
    Antenna
    Antique
    Arial
    Arimo
    Avant
    Barber1
    Barber2
    Barber3
    Barber4
    Birch
    Blackoak ...etc
    Now, I loop trough the content variable, extract each letter and add it to the "fontList[i]" array. If the character is a line break the fontList[i] array adds another element (i = i + 1); That's how I separate every single name into its own array element;
    The problem which I am having is, when I loop trough the fontList array and $.writeln(fontList[i]) the result in the console is:
    undefinedAlbertus
    undefinedAntenna
    undefinedAntique
    undefinedArial ...etc.
    I seriously don't get it, where the undefined is coming from? As far as I have tested each digit being added into the array element, I can't see anything out of ordinary.
    Here is my code:
    #target illustrator
    var doc = app.documents.add();
    //open file
    var myFile = new File ("c:/ScriptFiles/installedFonts-Families.txt");
    var openFile = myFile.open("r");
    //check if open
    if(openFile == true){
        $.writeln("The file has loaded")}
    else {$.writeln("The file did not load, check the name or the path");}
    //load the file content into a variable
    var content = myFile.read();
    myFile.close();
    var ch;
    var x = 0;
    var fontList = [];
    for (var i = 0; i < content.length; i++) {
        ch = content.charAt (i);
            if((ch) !== (String.fromCharCode(10))) {
                fontList[x] += ch;
            else {
                x ++;
    for ( i = 0; i < fontList.length; i++) {
       $.writeln(fontList[i]);
    doc.close (SaveOptions.DONOTSAVECHANGES);
    Thank you for any help or explanation. If you have any advice on how to improve my practices or any hint, please feel free to say. Thank you

    CarlosCantos wrote an amazing script a while back (2013) that may help you in your endeavor. Below is his code, I had nothing to do with this other then give him praise and I hope it doesn't offend him since it was pasted on the forums here.
    This has helped me do something similar to what your doing.
    Thanks again CarlosCanto
    // script.name = fontList.jsx;
    // script.description = creates a document and makes a list of all fonts seen by Illustrator;
    // script.requirements = none; // runs on CS4 and newer;
    // script.parent = CarlosCanto // 02/17/2013;
    // script.elegant = false;
    #target illustrator
    var edgeSpacing = 10;
    var columnSpacing = 195;
    var docPreset = new DocumentPreset;
    docPreset.width = 800;
    docPreset.height = 600;
    var idoc = documents.addDocument(DocumentColorSpace.CMYK, docPreset);
    var x = edgeSpacing;
    var yyy = (idoc.height - edgeSpacing);
    var fontCount = textFonts.length;
    var col = 1;
    var ABcount = 1;
    for(var i=0; i<fontCount; i++) {
        sFontName = textFonts[i].name;
        var itext = idoc.textFrames.add();
        itext.textRange.characterAttributes.size = 12;
        itext.contents = sFontName;
        //$.writeln(yyy);
        itext.top = yyy;
        itext.left = x;
        itext.textRange.characterAttributes.textFont = textFonts.getByName(textFonts[i].name);
        // check wether the text frame will go off the bottom edge of the document
        if( (yyy-=(itext.height)) <= 20 ) {
            yyy = (idoc.height - edgeSpacing);
            x += columnSpacing;
            col++;
            if (col>4) {
                var ab = idoc.artboards[ABcount-1].artboardRect;
                var abtop = ab[1];
                var ableft = ab[0];
                var abright = ab[2];
                var abbottom = ab[3];
                var ntop = abtop;
                var nleft = abright+edgeSpacing;
                var nbottom = abbottom;
                var nright = abright-ableft+nleft;
                var abRect = [nleft, ntop, nright, nbottom];
                var newAb = idoc.artboards.add(abRect);
                x = nleft+edgeSpacing;
                ABcount++;
                col=1;
        //else yyy-=(itext.height);

  • Quick question about null terminator string in arrays?

    Hello,
    If I do this:
    char volatile xxo_[20];
    memset(xxo_, ' ', 20);
    xxo_[1] = '\0';                                                                             
    Am I not supposed to see the '0' symbolizing the null terminated string in 2nd array location like this:
    xxo_[]= {' ','0',' ',' ',' ',' ',' ',' ',' ',' ' ,' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ',} 
    Why am I seeing this?
    xxo_[]= {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ' ,' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ',} 
    Thanks for all replies!

    Standard debugging paranoia applies.
    Are you running the code you think you are?  Do you need to recompile / rebuild / check your .exe against your source?  Do you just have a corrupt .pdb that needs to be rebuilt?  Nuke your exe and pdbs and start again.
    Try introducing a source code error or something that won't compile to verify that you are running the code you think you are compiling.  And if that works, then alter the program to do something else that you are expecting to work.  For example,
    change the memset ' ' to write an 'x' or something and see if you can observe that in your debugger.
    This is obviously not a standalone reproduction of the problem.  Try to avoid introducing other aspects that might contribute to confusing the issue.  Can you write a simple hello-world-sized program that does just this without all the rest of
    your program?
    char volatile to_[20];
    memset( (void*)to_, ' ', 20 );
    to_[0] = 0;
    Note that without the (void*) this won't compile in Visual C++ because of the
    volatile qualifier.
    What does the disassembly say?  Does the code that was generated logically do what the C code you wrote is intended to do?  Can you generate an assembly listing and examine that for logical flaws?
    Are you building with any kind of optimization settings?  sometimes breakpoints aren't where you think they are in "release mode" or optimized builds because instructions can be reordered and entire blocks of statements may be altered in ways
    that don't affect the final results, but make things a bit mysterious during debugging.
    Can you try a different debugger such as windbg and see if you observe the same thing?

  • Question about C array initialization

    I understand that the statement
    char string[] = "chars";
    initializes string[5] to 0 ('\000'). My question is does the statement
    char *strings[] = { "string1", "string2", "string3" };
    initialize strings[3] to (void *) 0, i.e. NULL? I can't find the answer to this question in the ansi standard. GCC seems to tack on a NULL pointer at the end (even with the -ansi and -pedantic-errors flags), which is really convenient for finding the boundary, but I'm not sure whether it's a GCC thing or an official C thing. I see where the standard talks about terminating char arrays initialized by a string literal with a null byte, but it doesn't talk about the analogous case with arrays of pointers.
    Last edited by nbtrap (2012-06-25 03:18:20)

    nbtrap wrote:
    Not necessarily. A declaration like:
    char arr[3] = "str";
    doesn't get null-terminated.
    It doesn't get null-terminated because you don't leave enough room in the array for the null character. "char arr[3]" can only contain 3 characters, the same way that "char arr[2] = "str" will only contain 2. The second example generates a warning whereas the first does not, but only because it is very common to work with non-null-terminated strings.
    nbtrap wrote:
    And besides, my point is that initializing strings[3] *would* make sense for the same reason that intializing
    char foo[] = "bar";
    with a terminating null byte *does* make sense.
    I know that arrays of pointers are not the same. My questions assumes that much. The fact of the matter is, however, GCC terminates pointer arrays of unknown size with a null pointer, and my question is simply "is this an ansi C thing or a GCC thing?".
    In fact, it seems that GCC terminates all arrays of unknown size that are explicitly initialized with the appropriate number of null bytes. For example:
    struct tag { int i; char c; char *str; } tags[] = {
    { 1, 'a', "string1" },
    { 2, 'b', "string2" },
    { 3, 'c', "string3" }
    initializes tags[3] to sizeof (struct tag) null bytes. Try it for yourself.
    I get the following:
    test.c
    #include <stdio.h>
    int
    main(int argc, char * * argv)
    int i;
    char *strings[] = { "string1", NULL, "string3"};
    for (i=0;i<5;i++)
    printf("strings[%d]: %s\n", i, strings[i]);
    return 0;
    output
    strings[0]: string1
    strings[1]: (null)
    strings[2]: string3
    Segmentation fault
    test2.c
    #include <stdio.h>
    #include <string.h>
    int
    main(int argc, char * * argv)
    int i;
    struct tag {int i; char c; char *str;};
    struct tag null;
    memset(&null, 0, sizeof(struct tag));
    struct tag tags[] =
    { 1, 'a', "string1" },
    // { 2, 'b', "string2" },
    null,
    { 3, 'c', "string3" }
    for (i=0;i<5;i++)
    printf(
    "tags[%d]: (%p) %1d %c %s\n",
    i, tags + i, tags[i].i, tags[i].c, tags[i].str
    return 0;
    output
    tags[0]: (0x7fffd2df4e80) 1 a string1
    tags[1]: (0x7fffd2df4e90) 0 (null)
    tags[2]: (0x7fffd2df4ea0) 3 c string3
    tags[3]: (0x7fffd2df4eb0) 0 (null)
    Segmentation fault
    The above behavior appears to conflict.
    Given that string constants in C are defined as null-terminated, i.e. "str" is equivalent to "{'s', 't', 'r', '\0'}", the assignment 'arr[] = "str"' explicitly includes a null terminator. The other examples above do not include such a terminator. Even if it would be convenient sometimes, the standard should adopt a minimally invasive approach. It's easy to add a NULL at the end of an array declaration, but impossible to remove an extra element from such a declaration.
    This may be informative too:
    test3.c
    #include <stdio.h>
    #include <string.h>
    int
    main(int argc, char * * argv)
    char str[] = "test";
    char *strings[] = {"string1", NULL, "string3"};
    struct tag {int i; char c; char *str;};
    struct tag null;
    memset(&null, 0, sizeof(struct tag));
    struct tag tags[] =
    { 1, 'a', "string1" },
    // { 2, 'b', "string2" },
    null,
    { 3, 'c', "string3" }
    printf(
    "str\n size: %lu\n length: %lu\n"
    "strings\n size: %lu\n length: %lu\n"
    "tags\n size: %lu\n length: %lu\n",
    sizeof(str), sizeof(str)/sizeof(char),
    sizeof(strings), sizeof(strings)/sizeof(char *),
    sizeof(tags), sizeof(tags)/sizeof(struct tag)
    return 0;
    output
    str
    size: 5
    length: 5
    strings
    size: 24
    length: 3
    tags
    size: 48
    length: 3
    The string length (actual number of chars in array) is reported as 5 ('t', 'e', 's', 't', '\0'), which is expected. The array of strings and tags are both reported as 3, even though you can access a null value after the last initialized index of the tags array. If that null value was really supposed to be there, it should be accounted for using sizeof, just as the null character is in the string.
    Maybe the ultimate null element of the tags array is some artefact of memory alignment.

  • Quick question about null terminator string!

    Hello,
    I always feel that a char array should end with a "\0".
    But just to clear up something here, if I do:
    char *a[10];
    and I fill out the array with 10 characters, then, should we *always* append the "\0" at the end of this array?
    And if so, should it be appended at a[9] location or a[10] ??? It confuses me a little because since the array is supposed to take 10 characters, then does the compiler save an extra space at the 11th character location for the null terminator string?
    OR
    Is it up to us to make sure we fill the array with up to 9 characters making sure to save the 10th location in the array for the null terminator string?
    So in a nutshell, once we finish up with a char array do we do this:
    a[9] = '\0';
    or this:
    a[10] = '\0';
    I excuse the simple question but this has been haunting me for a while, but thanks for all replies!!!
    r

    Ok, a few misconceptions here.
    I always feel that a char array should end with a "\0".
    This is not strictly true.  This is only true of the data is to be treated as a string.  Often you will use a char array to hold binary data.  Normally such binary data will NOT end in a NUL character.  In fact, most binary data may contain
    NUL characters sprinkled throughout the data.
    char *a[10];
    This is NOT an array of ten characters.  This is an array of ten pointers to characters (or character arrays).  You probably intended
    char a[10];
    You then state
    I fill out the array with 10 characters, then, should we *always* append the "\0" at the end of this array?
    Again, this depends on whether you intend the data to be a string or binary data.  I will assume you mean string from here on out.  For a string, yes you should probably always append a '\0' Of course you don't actually have room for that NUL --
    see the following answer.  (Actually there are some string APIs that let you pass in a number of characters to process and those will work with no terminating NUL, but frankly you are playing with fire when you do that so I would recommend always putting
    the trailing NUL in myself.)
    And if so, should it be appended at a[9] location or a[10]
    The declaration "char a[10]" causes the compiler to reserve *exactly* ten bytes of data for that array.  If you write to location a[10], that is the
    eleventh byte and will cause undefined behavior.  At best you might not notice anything bad.  At worst it could cause any sort of crazy data corruption.  It could easily crash your program.
    You would need to write the NUL character at a[9].   Note that writing NUL at a[9] will overwrite the last byte that you put into that array.
    As a side note here:  This is why you try to always use a proper string class like std::string when using C++ -- it takes care of all of that for you, including growing the string larger if you fill it up.  Then you don't need to worry
    about these pesky details that are easy to get wrong.

  • Question about sorting arrays

    Hi,
    I have posted information from an one-dimensional array on to a list widget. When a user selects an item in the list(index value = 3), presses the delete button, the item would be removed. Likewise, the element of the array at index value 3 would also be removed (or set to null?).
    The trouble I am having is, how would you move up the elements that are subsequent to the element index value 3? For example, moving element index value 4 up to 3, 5 up to 4, 6 up to 5....etc.?
    Here is my code:
    public void delete()
    list.delItem(list.getSelectedIndex());
    student[list.getSelectedIndex()]=null;
    Thanks alot!!

    It's usually faster to use System.arraycopy() to close up the "hole" when removing something from an array: public void delete() {
        int index = list.getSelectedIndex() ;
        list.delItem(index) ;
        // if not removing last item... close up hole...
        if (index < (student.length-1)) {
            System.arraycopy(student, index+1, student, index, student.length - 1 - index) ;
        // clear out space made empty at end of array
        student[student.length-1] = null ; // or whatever represents 'empty' in your student[]

  • Question about string array?

    Hello,
    When passing Stting arrays to a function, is there anyto test if the array is emply?
    void testFucntion(String[] test){
    }

    Or test the array is null.
    if (test == null || test.length == 0)

  • Question about an Array of objects

    I'm writing a program that is supposed to store a String and a double in an array of CustomerBill objects. I just want to know if I am doing it correctly. Heres my code:
    public static CustomerBill[] getCustomerData()
             //Local variables
             int numCust;     //The number of customers being processed
             double amt;
             String customer;        
          //Ask for the number of customers to be processed.
             System.out.print("How many customers are to be processed? ");
             numCust = Integer.parseInt(keyboard.nextLine());
             CustomerBill[] array = new CustomerBill[numCust];
             //Ask user to enter the data.
             System.out.println("\nPlease enter customer data when prompted.");
             System.out.println("Enter customer's last name, then first name.");
          //Get the customer data from user.
             for (int i = 0; i < array.length; i++)
               array[i] = new CustomerBill();
               System.out.print("\nCustomer name:  ");
               customer = keyboard.nextLine();       
               array.setName(customer);
    System.out.print("Total bill amount: ");
    amt = Double.parseDouble(keyboard.nextLine());
    array[i].setAmount(amt);
    System.out.println();
    return array;

    Write a test() method that:
    (1) Gets an array of CustomerBills using getCustomerData()
    (2) In a for-loop print out each of the CustomerBills. It will help if
    CustomerBill has a toString() method but, in any case you should be
    able to see that the aray contains the right number of nonnull elements.
    Then write a main() method that calls the test() method.
    [Edit] And then run it! You may need to do this a few times and check
    what happens with "crazy" data.

  • Question about using arrays

    I have a web page written with combination of Front Page and Java is included. I have 4 drop down boxes which work in sequence. select an item in the first, it then asks you to select in the second box, then 3rd then in the final 4th box. This was set up using arrays. My question is how can i put a hyperlink to the items in the last drop down box? I want the last selection to go to a URL. can you tell me what code i need to use and where to insert it? I assume it has to go into the array somewhere. Thanks, Tom

    selection to go to a URL. can you tell me what code
    i need to use and where to insert it? Not without you clarifying your question and showing the relevant bits of your code, and possibly not even then.
    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    I assume it
    has to go into the array somewhere. I assume it doesn't, because code doesn't go into arrays.

  • Questions about Adobe Photoshop Elements 13

    Can Adobe Photoshop Elements 13 show a pixillated version of a subject?  Can it show just the edges of the subject?

    Those effects are in the Filters palette in Expert mode.
    Suggestion: download the trial version and see if that's what you want.

  • Question about the Arrays utility

    Can I use the util.Arrays library to sort multi dimentional arrays? I dont see methods for that in the documentation, so I am guessing no.

    Yes it is. what kind of a comparetor would I need to set up for an int[][] array which I wish to sort in descending order according to the second dimension?
    Also, can you copy an array without using a for loop? I know that doing a = b (where a and b are both arrays of the same type) just passes a a referene to b.

  • Question about Object Arrays

    I am getting compile time error of missing ']' on the second line
        dvdData[] data = new dvdData[4];
        data[0] = new dvdData("Casablanca", "Warner Brothers", "1942");
        data[1] = new dvdData("Citizen Kane", "RKO Pictures", "1941");
        data[2] = new dvdData("Singin' in the Rain", "MGM", "1952");
        data[3] = new dvdData("The Wizard of Oz", "MGM", "1939");the object dvdData is being declared correctly with 3 strings as constructors, can anyone tell me why it is doing this? I will post complete code if nessecary.

    Hi,
    I don't see any problem - check out my code :-
    package project1;
    public class DVDData
        String str1 = null;
        String str2 = null;
        String str3 = null;
        public DVDData(String str1,String str2,String str3)
            this.str1=str1;
            this.str2=str2;
            this.str3=str3;
        public String toString()
            return str1 + " : " +    str2 + " : " + str3;
        public static void main(String[] args)
            DVDData[] data = new DVDData[4];
            data[0] = new DVDData("Casablanca", "Warner Brothers", "1942");
            data[1] = new DVDData("Citizen Kane", "RKO Pictures", "1941");
            data[2] = new DVDData("Singin' in the Rain", "MGM", "1952");
            data[3] = new DVDData("The Wizard of Oz", "MGM", "1939");
            System.out.println(data[0]);
            System.out.println(data[1]);
            System.out.println(data[2]);
            System.out.println(data[3]);
    }I get the correct output :-
    Casablanca : Warner Brothers : 1942
    Citizen Kane : RKO Pictures : 1941
    Singin' in the Rain : MGM : 1952
    The Wizard of Oz : MGM : 1939How are you comipling this ?
    Regards,
    Sandeep

  • Question about Java Array Primative Type.

    Say I create an Array of type Integer, like this:
    Integer [] myArray = new Integer[10];
    I now have an Integer array, 10 cells big.
    However, I have now learned that I can do the following:
    String [] [] [] stringArray = new String [3][3][3];
    I can create higher dimensional arrays!
    Is there any limit to the degree/dimension such an array may be,
    and does the Array class presently support any methods, like getDimension,
    to check the number of indices on an array where the number of indicies/dimensions
    are a priori unknown?

    And as far as I know, their is not limit to the depth of the arrays as long as you stay within the memory boundaries.In practice the depth is limited by the range of a Java 'int', because the array descriptor in the .class file is a String starting with the appropriate number of [ characters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • A question about "null" ?

    I have problems when I read data from a database and the query returns me a "null". how can I put or compare this "null" to a byte[] varible?

    to assign or compare a null value to a byte[], try this:
    byte[] b = null;  // assigning null
    byte[] b1 = b;  // assign object which is null.
    if (b == b1) { // comparing two null objects.
      System.out.println("Same.");
    if (b == null) { // comparing object to null.
      System.out.println("Same.");
    }

  • I have question about null and undefined?

    I tested null and undefined all single character.
    I saw abnormal result
    /* test code */
    var A:String
    var Z:String
    var a:String
    var z:String
    trace("A: " + A);
    trace("Z: " + Z);
    trace("");
    trace("a: " + a);
    trace("z: " + z);
    /* End of test code */
    I tested this code on Flash 8.
    /* result */
    A: undefined
    Z: undefined
    a: undefined
    n: undefined
    o: null
    p: undefined
    z: undefined
    /* End of result */
    Only 'o' make different result.
    It is same result on Flash Player 8 and Flash Player 9.
    Please, tell me why.
    Thanks
    /* code generation code */
    type = "String"; //Number, Movieclipe ...
    for (i = 65; i < 91; i++)
    trace("var " + String.fromCharCode(i) + ":" + type);
    trace("");
    for (i = 97; i < 123; i++)
    trace("var " + String.fromCharCode(i) + ":" + type);
    trace("");
    for (i = 65; i < 91; i++)
    trace("trace(\"" + String.fromCharCode(i) + ": \" + " +
    String.fromCharCode(i) + ");");
    trace("trace(\"\");");
    for (i = 97; i < 123; i++)
    trace("trace(\"" + String.fromCharCode(i) + ": \" + " +
    String.fromCharCode(i) + ");");
    /* End of code generation code */

    kyduke,
    > I tested null and undefined all single character.
    > I saw abnormal result
    I can't reproduce your results. I used the exactl block of
    code you
    designated as ...
    /* code generation code */
    ... and all my trace() results are consistent.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

Maybe you are looking for