Cannot find symbol java error (newbie question)

Discussion in 'Java' started by Taria, Sep 29, 2007.

  1. Taria

    Taria Guest

    Hello all!

    I'm normally good at finding why a java compiler can't find a symbol,
    the methods have different calling types in their parameters,
    mispelling of a variable, certain letters were captialized while
    others were not but this has me totally stumped. Here is a simplified
    version of my program.

    import java.util.*;
    import java.lang.*;

    public class myProg{

    public static void main(String[] arguments) {
    int size = 10; // arbritray size - test number
    LinkedList [] bucketArray = new LinkedList[size];

    // next try to insert the value into bucket array
    //bucketArray[1] = array[0]; incompatible types (my first
    attempt to assign a value :p)

    Integer four = new Integer(4); //so now four is an object
    bucketArray.insert(four,0); //cannot find symbol
    } //end of main

    class LinkedList{
    private Node head;
    private int length;

    public LinkedList() {
    this.head = null;
    this.length = 0;
    }

    public void insert (Object data,int position){
    System.out.println ("Node code here\n");

    }
    }

    Essentially, I'm trying to initiialize the bucketArray with a value.
    I really want the cell of the array to hold a string of characters but
    for simplicity sake I made it into an integer for now just to get it
    compiling. When I shortened this program to post it here, I took out
    the existing Node class that I put in place, but I don't think this
    should affect anything (at least I hope it doesn't.)

    So, what is wrong? I am passing 2 parms, one object, the other an
    int...I think I'm referencing it correctly to call 'insert' within the
    LinkedList class. I've checked and rechecked it and frankly, I'm
    stumped.

    Sidenote: from past advice, I understand that the array is really
    holding a reference in the array I created. That doesn't really
    affect me, does it? Isn't that internal? Is there a special way to
    specify whether it is a reference or whetehr it holds a specific
    value?

    Any help is again appreciated,
    -t (the
    Taria, Sep 29, 2007
    #1
    1. Advertising

  2. Taria wrote:

    Sub: Cannot ... (newbie question)

    A good group for newbies is comp.lang.java.help.

    >I'm normally good at finding why a java compiler can't find a symbol,
    >the methods have different calling types in their parameters,
    >mispelling of a variable, certain letters were captialized while
    >others were not but this has me totally stumped. Here is a simplified
    >version of my program.


    Uggh.. Simplified perhaps, but badly formatted (please do
    not indent the code sample, it is better to delimit the start
    and end of the code with tags like <code></code>, or far
    better <sscce></sscce>*), missing the closing '}', and with
    lines so long they wrap, thereby causing further compilation
    problems.

    ...
    >...When I shortened this program to post it here, I took out
    >the existing Node class ..


    * Please don't do that. An SSCCE is usually far better
    at both expressing a problem, and encouraging others
    to help solve it. For more info. on the SSCCE, see
    <http://www.physci.org/codes/sscce.html>

    >..that I put in place, but I don't think this
    >should affect anything (at least I hope it doesn't.)


    It sure affects the level of my motivation to assist.
    A (very) few people around these parts enjoy trying
    to spot programming problems 'by eye'. The rest of
    us prefer to see the compilation or runtime errors
    on-screen. An SSCCE allows us to do that.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
    Andrew Thompson, Sep 29, 2007
    #2
    1. Advertising

  3. Taria

    Taria Guest

    On Sep 29, 12:02 am, "Andrew Thompson" <u32984@uwe> wrote:
    > Taria wrote:
    >
    > Sub: Cannot ... (newbie question)
    >
    > A good group for newbies is comp.lang.java.help.
    >
    > >I'm normally good at finding why a java compiler can't find a symbol,
    > >the methods have different calling types in their parameters,
    > >mispelling of a variable, certain letters were captialized while
    > >others were not but this has me totally stumped. Here is a simplified
    > >version of my program.

    >
    > Uggh.. Simplified perhaps, but badly formatted (please do
    > not indent the code sample, it is better to delimit the start
    > and end of the code with tags like <code></code>, or far
    > better <sscce></sscce>*), missing the closing '}', and with
    > lines so long they wrap, thereby causing further compilation
    > problems.
    >
    > ..
    >
    > >...When I shortened this program to post it here, I took out
    > >the existing Node class ..

    >
    > * Please don't do that. An SSCCE is usually far better
    > at both expressing a problem, and encouraging others
    > to help solve it. For more info. on the SSCCE, see
    > <http://www.physci.org/codes/sscce.html>
    >
    > >..that I put in place, but I don't think this
    > >should affect anything (at least I hope it doesn't.)

    >
    > It sure affects the level of my motivation to assist.
    > A (very) few people around these parts enjoy trying
    > to spot programming problems 'by eye'. The rest of
    > us prefer to see the compilation or runtime errors
    > on-screen. An SSCCE allows us to do that.
    >
    > --
    > Andrew Thompsonhttp://www.athompson.info/andrew/
    >
    > Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1


    I see.

    I'll check it out, Andrew. Currently, I don't know what that is but
    I'll educate myself on it and see if I can use that instead.

    Thanks
    Taria, Sep 29, 2007
    #3
  4. Taria

    Taria Guest

    I'm sorry I offended you, Andrew. The indents on my program is fine
    in my java GUI but pasting it here seems to have messed with
    indentation some. I will repair it now for your easy viewing.

    Also, I recompiled my shortened version prior to posting it here and
    it replicates the problem exactly. I trimmed everything out that was
    extraneous and I really do think I followed that SSCCE web site
    intuitively (it's common sense.) I liked that SSCCE page, it's nice
    to have it in black and white and the author has a friendly and
    helpful composure about him.

    import java.util.*;
    import java.lang.*;

    public class myProg{

    public static void main(String[] arguments) {
    int size = 10;
    LinkedList [] bucketArray = new LinkedList[size];

    Integer four = new Integer(4); //so now four is an object
    bucketArray.insert(four,0); //cannot find symbol
    } //end of main

    class LinkedList{
    private Node head;
    private int length;

    public LinkedList() {
    this.head = null;
    this.length = 0;
    }

    public void insert (Object data,int position){
    System.out.println ("Node code here\n");
    //irrevelant what i do in here since this thing
    //never compiles
    }
    }

    Ok, well, this program can be cut and pasted and it will recompile
    with the error I posted about (it's the same program as in my original
    post but prettier to look at it.) :)

    -t
    Taria, Sep 29, 2007
    #4
  5. Taria

    Taria Guest

    On Sep 29, 12:38 am, Taria <> wrote:
    > I'm sorry I offended you, Andrew. The indents on my program is fine
    > in my java GUI but pasting it here seems to have messed with
    > indentation some. I will repair it now for your easy viewing.
    >
    > Also, I recompiled my shortened version prior to posting it here and
    > it replicates the problem exactly. I trimmed everything out that was
    > extraneous and I really do think I followed that SSCCE web site
    > intuitively (it's common sense.) I liked that SSCCE page, it's nice
    > to have it in black and white and the author has a friendly and
    > helpful composure about him.
    >
    > import java.util.*;
    > import java.lang.*;
    >
    > public class myProg{
    >
    > public static void main(String[] arguments) {
    > int size = 10;
    > LinkedList [] bucketArray = new LinkedList[size];
    >
    > Integer four = new Integer(4); //so now four is an object
    > bucketArray.insert(four,0); //cannot find symbol
    > } //end of main
    >
    > class LinkedList{
    > private Node head;
    > private int length;
    >
    > public LinkedList() {
    > this.head = null;
    > this.length = 0;
    > }
    >
    > public void insert (Object data,int position){
    > System.out.println ("Node code here\n");
    > //irrevelant what i do in here since this thing
    > //never compiles
    > }
    > }
    >
    > Ok, well, this program can be cut and pasted and it will recompile
    > with the error I posted about (it's the same program as in my original
    > post but prettier to look at it.) :)
    >
    > -t


    I'm sorry guys. I missed a curly braces at the very end of my cut and
    paste in my hurry to fix this error. :(

    I"m near ready to give this thing up...but I think I'll just sleep on
    it for now and whatever, I seriously don't want to relist this
    program again just for ONE curly bracer at the end (the left one)...so
    to those that are in the right set of mind and tried to compile, add a
    "}" at the end of the program and then that will be a complete
    uncompilable replicated verseion of my program.

    It's Friday night and I'm here! Lol, oh my.
    -t
    Taria, Sep 29, 2007
    #5
  6. Taria <> writes:

    > I'm sorry I offended you, Andrew. The indents on my program is fine
    > in my java GUI but pasting it here seems to have messed with
    > indentation some. I will repair it now for your easy viewing.


    I can't talk for Andrew, but suggestions to fix up the code and make
    a SSCCE is generally meant as a help. It really does make a difference
    about who wants to invest time in helping with the problem.

    > int size = 10;
    > LinkedList [] bucketArray = new LinkedList[size];


    bucketArray is an array, not a LinkedList ...

    > Integer four = new Integer(4); //so now four is an object
    > bucketArray.insert(four,0); //cannot find symbol


    .... and arrays don't have an "insert" method.
    Do you mean "bucketArray[0].add(four);"?


    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 29, 2007
    #6
  7. Taria

    Roedy Green Guest

    On Sat, 29 Sep 2007 02:34:22 -0700, Taria <> wrote,
    quoted or indirectly quoted someone who said :

    > import java.util.*;
    > import java.lang.*;
    >
    > public class myProg{
    >
    > public static void main(String[] arguments) {
    > int size = 10; // arbritray size - test number
    > LinkedList [] bucketArray = new LinkedList[size];
    >
    > // next try to insert the value into bucket array
    > //bucketArray[1] = array[0]; incompatible types (my first
    >attempt to assign a value :p)
    >
    > Integer four = new Integer(4); //so now four is an object
    > bucketArray.insert(four,0); //cannot find symbol
    > } //end of main
    >
    > class LinkedList{
    > private Node head;
    > private int length;
    >
    > public LinkedList() {
    > this.head = null;
    > this.length = 0;
    > }
    >
    > public void insert (Object data,int position){
    > System.out.println ("Node code here\n");
    >
    > }
    > }


    I have corrected your program as follows.

    import java.util.*;
    import java.lang.*;

    /** shows compiler error message */
    public class MyProg
    {

    public static final int MAX_BUCKETS = 10; // arbitrary size - test
    number


    public static void main(String[] arguments)
    {
    // create an array of LinkedLists
    LinkedList [] bucketArray = new LinkedList[ MAX_BUCKETS ];

    // next insert value into bucket array

    // bucketArray uses array[] syntax, the LinkList contents use
    method syntax.
    Integer four = new Integer(4); //so now four is an object
    // need to create an LinkedList to add to the array, not an
    Object
    LinkedList ll = new LinkedList();
    ll.insert ( four, 0 );
    // now add the linked list to the array.
    bucketArray[0] = ll;

    } //end of main
    }

    /** top level class to implement a LinkedList */

    class LinkedList
    {
    private Node head;
    private int length;

    public LinkedList()
    {
    this.head = null;
    this.length = 0;
    }

    public void insert (Object data,int position)
    {
    System.out.println ("Node code here\n");
    }
    }

    /** SSCCE was missing a node class. We provide a dummy one */
    class Node
    {
    }


    You are confused between arrays and Lists. You rarely need both.

    You could either have an array of objects or a LinkedList of Objects,
    but you normally would not have an array of LinkedLists of Objects.

    See http://mindprod.com/jgloss/array.html
    http://mindprod.com/jgloss/arraylist.html

    LinkedLists in general are rare since they are slower than other sorts
    of lists most of the time. The beauty of the List interface is you can
    try several list implementations to see which actually works best with
    minimal code change.

    Normally you would have an ArrayList<Dog> where Dog is some specific
    class. It is rare to see a List<Object> any more.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 29, 2007
    #7
  8. Taria

    Roedy Green Guest

    On Sat, 29 Sep 2007 03:38:34 -0700, Taria <> wrote,
    quoted or indirectly quoted someone who said :

    >I'm sorry I offended you, Andrew.

    Andrew thinks he is Gregory House/Sherlock Holmes and that his acidic
    style is entertaining. He was hired by Microsoft to haze newbies in
    an attempt to derail Java by frightening off potential programmers.

    He wishes he were a computer. Like the child on StarTrek NG who
    developed a serious case of hero worship on Data, he likes to
    fantasize he is an android by posturing as absurdly literal, this
    simulates rigorous objectivity. He imagines computers are that way,
    and that is what makes them superior life forms.

    He is a bit of a nutter, but if you ignore his mild anally retentive
    Tourette's tics' he can be a useful tutor.

    I know another person like him who lives in Somerset in England. If
    you read a transcript of the things he said you would imagine him foul
    mouthed and mean. But if you hear him live, you hear the merry laugh.
    It is his way of being jocular. c.f. the word "shut up" in black
    slang.
    see http://mindprod.com/ggloss/shutup.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 29, 2007
    #8
  9. Roedy Green wrote:
    >>I'm sorry I offended you, Andrew.

    >Andrew thinks ..


    You do not have the first clue what I think. Further,
    your block-headed tendencies will probably make
    you remain that way.

    To Taria. I am not offended, and intended the advice
    to help you.

    I hope my words did not cause you offence. If they did,
    I would be interested to hear why. It might not change
    the way I post, but it did somewhat surprise me that
    you thought any apologies were necessary.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
    Andrew Thompson, Sep 29, 2007
    #9
  10. Taria

    Taria Guest

    > You could either have an array of objects or a LinkedList of Objects,
    > but you normally would not have an array of LinkedLists of Objects.
    >
    > Seehttp://mindprod.com/jgloss/array.htmlhttp://mindprod.com/jgloss/arraylist.html
    >
    > LinkedLists in general are rare since they are slower than other sorts
    > of lists most of the time. The beauty of the List interface is you can
    > try several list implementations to see which actually works best with
    > minimal code change.
    >
    > Normally you would have an ArrayList<Dog> where Dog is some specific
    > class. It is rare to see a List<Object> any more.
    > --
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com- Hide quoted text -
    >
    > - Show quoted text -


    Lol, hey you want to see something rare? Come to my class and you'll
    see it in the flesh! (Just kidding!) My professor is brilliant but
    his homework assignments are old school. His reputation as a teacher
    is ...avoid at all costs but I"m actually enjoying his class even
    though I think I failed his midterm. And of course it's a required
    course, he's the only one that teaches it, yadda yadda yah..if other
    ppl can pass this course, so can I!

    Back to this program, his requirment for this program is that it's a
    bucket sort, where S= number of buckets N=data items and where S is
    not necessarily equal to N, thus collisions are possible. Thus, S =
    length of array and I figured I'd stick the references of the head in
    the first cell. Each cell of the array will contain the reference of
    the first Node of each list (but I'm a bit fuzzy how the program's
    going to know how to reference the nodes and such)

    >... and arrays don't have an "insert" method.
    >Do you mean "bucketArray[0].add(four);"?


    Oh yeah! so that's how you reference an array using OOP code.
    Thanks, Lasse, yes that's what I mean. I feel like I might be able to
    finish this after all..I can't wait to try it.

    Conceptually this is my solution: create an array of linked lists
    beacause this fits the picture he drew on the blackboard. Yes, I am
    confused about linked links and arrays. My internal picture keeps
    'switching' and I feel a contention when trying to work out the
    program logic when thinking about referrencing the array and trying to
    assign values to it.

    Interfaces? I'm going to have to read about that. I'm not familiar
    with interfaces even though I'm aware of their presence.

    I just learned about the class ArrayList today, thanks to you Roedy,
    interesting to see such a class available. A new subject to search
    the web when encountering unexpected errors when trying to use it. :)

    In any case, I have two things to try right now, thank you Lasse and
    Roedy.

    -t

    feeling hopeful at Java again. :p
    Taria, Sep 29, 2007
    #10
  11. Taria

    Roedy Green Guest

    On Sat, 29 Sep 2007 12:50:49 GMT, "Andrew Thompson" <u32984@uwe>
    wrote, quoted or indirectly quoted someone who said :

    >You do not have the first clue what I think.


    It does not matter. I am insulting you by pointing out what a nutter
    you appear to be to others in the hopes you will stop being so rude to
    the newbies. You dish out so many insults a day, it seems odd you
    whither at one mild one in return.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 30, 2007
    #11
  12. Taria

    Lew Guest

    Re: Flame war! [was: Cannot find symbol java error (newbie question)]

    "Andrew Thompson":
    >> You do not have the first clue what I think.


    Roedy Green wrote:
    > It does not matter. I am insulting you by pointing out what a nutter
    > you appear to be to others in the hopes you will stop being so rude to
    > the newbies. You dish out so many insults a day, it seems odd you
    > whither at one mild one in return.


    I want a nice clean fight. No hitting below the belt. Come out when the bell
    rings. Now shake hands, and back to your corners. Marquis of Queensbury rules.

    Ding.

    --
    Lew
    Lew, Sep 30, 2007
    #12
  13. Taria

    Daniel Pitts Guest

    On Sep 29, 2:34 am, Taria <> wrote:
    > Hello all!
    >
    > I'm normally good at finding why a java compiler can't find a symbol,
    > the methods have different calling types in their parameters,
    > mispelling of a variable, certain letters were captialized while
    > others were not but this has me totally stumped. Here is a simplified
    > version of my program.
    >
    > import java.util.*;
    > import java.lang.*;
    >
    > public class myProg{
    >
    > public static void main(String[] arguments) {
    > int size = 10; // arbritray size - test number
    > LinkedList [] bucketArray = new LinkedList[size];
    >
    > // next try to insert the value into bucket array
    > //bucketArray[1] = array[0]; incompatible types (my first
    > attempt to assign a value :p)
    >
    > Integer four = new Integer(4); //so now four is an object
    > bucketArray.insert(four,0); //cannot find symbol
    > } //end of main
    >
    > class LinkedList{
    > private Node head;
    > private int length;
    >
    > public LinkedList() {
    > this.head = null;
    > this.length = 0;
    > }
    >
    > public void insert (Object data,int position){
    > System.out.println ("Node code here\n");
    >
    > }
    > }
    >
    > Essentially, I'm trying to initiialize the bucketArray with a value.
    > I really want the cell of the array to hold a string of characters but
    > for simplicity sake I made it into an integer for now just to get it
    > compiling. When I shortened this program to post it here, I took out
    > the existing Node class that I put in place, but I don't think this
    > should affect anything (at least I hope it doesn't.)
    >
    > So, what is wrong? I am passing 2 parms, one object, the other an
    > int...I think I'm referencing it correctly to call 'insert' within the
    > LinkedList class. I've checked and rechecked it and frankly, I'm
    > stumped.
    >
    > Sidenote: from past advice, I understand that the array is really
    > holding a reference in the array I created. That doesn't really
    > affect me, does it? Isn't that internal? Is there a special way to
    > specify whether it is a reference or whetehr it holds a specific
    > value?
    >
    > Any help is again appreciated,
    > -t (the


    Look at this SSCCE:

    class MyClass {
    Integer[] array = new Integer[10];

    public void doSomething() {
    array.intValue(); /* fails, calling on the array instead of the
    element */
    array[0].intValue(); /* succeeds */
    for (int i = 0; i < array.length; ++i) {
    System.out.println(array.intValue()); /* succeeds */
    }
    }
    }
    Daniel Pitts, Sep 30, 2007
    #13
  14. Taria

    Lew Guest

    Daniel Pitts wrote:
    > Look at this SSCCE:
    >
    > class MyClass {
    > Integer[] array = new Integer[10];
    >
    > public void doSomething() {
    > array.intValue(); /* fails, calling on the array instead of the
    > element */
    > array[0].intValue(); /* succeeds */
    > for (int i = 0; i < array.length; ++i) {
    > System.out.println(array.intValue()); /* succeeds */
    > }
    > }
    > }


    These calls marked "succeeds", while they successfully compile, only succeed
    at runtime if each invoked array element is non-null.

    This is not relevant to the compilation issue but might be important to those
    who forget that newsgroup examples sometimes intentionally omit details for
    pedagogical purposes that would be problematic in actual production. In
    production code one would anticipate a NullPointerException.

    --
    Lew
    Lew, Sep 30, 2007
    #14
  15. Taria

    Taria Guest


    > To Taria. I am not offended, and intended the advice
    > to help you.
    >
    > I hope my words did not cause you offence. If they did,
    > I would be interested to hear why. It might not change
    > the way I post, but it did somewhat surprise me that
    > you thought any apologies were necessary.
    >
    > --
    > Andrew Thompsonhttp://www.athompson.info/andrew/
    >
    > Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1


    Thanks Andrew, this message made me feel better and I appreciate you
    asking why I felt that way.

    My analysis of why is this: First, know that I was already feeling
    bad at not being able to figure out the program's error and by the
    time I come here, I'm fustrated. This forum gives me hope.

    I know this is an informal way of online communication (forums in any
    case) but if you were to compare, say the style of the SSCCE's web
    page (the one you linked) and what you posted..they essentially say
    the same thing...but in different ways. The state of 'feeling bad'
    existed in both cases, but the SSCCE's webpage I enjoyed reading and I
    walked away from it feeling ok about myself. If you want specific
    examples, I can go into it...but in general that's it in a nutshell.

    I understand you were trying to help now. Thank you. :)
    Taria, Oct 2, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny
    Replies:
    1
    Views:
    4,664
    Andrew Thompson
    May 26, 2004
  2. luch
    Replies:
    5
    Views:
    6,335
  3. powah
    Replies:
    5
    Views:
    2,081
    Arne Vajhøj
    Mar 22, 2009
  4. nalbertini

    Java - cannot find symbol

    nalbertini, Feb 12, 2011, in forum: Java
    Replies:
    1
    Views:
    763
    nalbertini
    Feb 12, 2011
  5. Replies:
    6
    Views:
    1,726
Loading...

Share This Page