Cannot find symbol java error (newbie question)

  • Follow


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 whileothers were not but this has me totally stumped.  Here is a simplifiedversion 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 firstattempt 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 butfor simplicity sake I made it into an integer for now just to get itcompiling.  When I shortened this program to post it here, I took outthe existing Node class that I put in place, but I don't think thisshould affect anything (at least I hope it doesn't.)So, what is wrong?  I am passing 2 parms, one object, the other anint...I think I'm referencing it correctly to call 'insert' within theLinkedList class.  I've checked and rechecked it and frankly, I'mstumped.Sidenote:  from past advice, I understand that the array is reallyholding a reference in the array I created.  That doesn't reallyaffect me, does it?  Isn't that internal?  Is there a special way tospecify whether it is a reference or whetehr it holds a specificvalue?Any help is again appreciated,-t (the
0
Reply mchew02 (18) 9/29/2007 9:34:22 AM

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

0
Reply Andrew 9/29/2007 10:02:14 AM


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/1I see.I'll check it out, Andrew.  Currently, I don't know what that is butI'll educate myself on it and see if I can use that instead.Thanks
0
Reply Taria 9/29/2007 10:11:12 AM

I'm sorry I offended you, Andrew.  The indents on my program is finein my java GUI but pasting it here seems to have messed withindentation some.  I will repair it now for your easy viewing.Also, I recompiled my shortened version prior to posting it here andit replicates the problem exactly.  I trimmed everything out that wasextraneous and I really do think I followed that SSCCE web siteintuitively (it's common sense.)  I liked that SSCCE page, it's niceto have it in black and white and the author has a friendly andhelpful 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 recompilewith the error I posted about (it's the same program as in my originalpost but prettier to look at it.)  :)-t
0
Reply Taria 9/29/2007 10:38:34 AM

On Sep 29, 12:38 am, Taria <mche...@hotmail.com> 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.)  :)>> -tI'm sorry guys.  I missed a curly braces at the very end of my cut andpaste in my hurry to fix this error.  :(I"m near ready to give this thing up...but I think I'll just sleep onit for now and whatever,  I seriously don't want to relist thisprogram again just for ONE curly bracer at the end (the left one)...soto 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 completeuncompilable replicated verseion of my program.It's Friday night and I'm here!  Lol, oh my.-t
0
Reply Taria 9/29/2007 10:47:06 AM

Taria <mchew02@hotmail.com> 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 makea SSCCE is generally meant as a help. It really does make a differenceabout 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  -  lrn@hotpop.com DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>  'Faith without judgement merely degrades the spirit divine.'
0
Reply Lasse 9/29/2007 11:03:11 AM

On Sat, 29 Sep 2007 02:34:22 -0700, Taria <mchew02@hotmail.com> 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 - testnumber   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 usemethod syntax.      Integer four = new Integer(4);  //so now four is an object      // need to create an LinkedList to add to the array, not anObject      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.htmlhttp://mindprod.com/jgloss/arraylist.htmlLinkedLists in general are rare since they are slower than other sortsof lists most of the time. The beauty of the List interface is you cantry several list implementations to see which actually works best withminimal code change.Normally you would have an ArrayList<Dog> where Dog is some specificclass.  It is rare to see a List<Object> any more.-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
0
Reply Roedy 9/29/2007 11:12:19 AM

On Sat, 29 Sep 2007 03:38:34 -0700, Taria <mchew02@hotmail.com> 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 acidicstyle is entertaining.  He was hired by Microsoft to haze newbies inan attempt to derail Java by frightening off potential programmers.He wishes he were a computer. Like the child on StarTrek NG whodeveloped a serious case of hero worship on Data, he likes tofantasize he is an android by posturing as absurdly literal, thissimulates 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 retentiveTourette's tics' he can be a useful tutor.I know another person like him who lives in Somerset in England. Ifyou read a transcript of the things he said you would imagine him foulmouthed 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 blackslang.see http://mindprod.com/ggloss/shutup.html-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
0
Reply Roedy 9/29/2007 11:31:30 AM

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 Thompsonhttp://www.athompson.info/andrew/Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
0
Reply Andrew 9/29/2007 12:50:49 PM

> 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


0
Reply Taria 9/29/2007 5:51:37 PM

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 nutteryou appear to be to others in the hopes you will stop being so rude tothe newbies. You dish out so many insults a day, it seems odd youwhither at one mild one in return.-- Roedy Green Canadian Mind ProductsThe Java Glossaryhttp://mindprod.com
0
Reply Roedy 9/30/2007 7:46:35 AM

"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
0
Reply Lew 9/30/2007 3:53:37 PM

On Sep 29, 2:34 am, Taria <mche...@hotmail.com> 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 (theLook at this SSCCE:class MyClass {   Integer[] array = new Integer[10];   public void doSomething() {      array.intValue(); /* fails, calling on the array instead of theelement */      array[0].intValue(); /* succeeds */      for (int i = 0; i < array.length; ++i) {         System.out.println(array[i].intValue()); /* succeeds */      }   }}
0
Reply Daniel 9/30/2007 5:19:03 PM

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[i].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
0
Reply Lew 9/30/2007 7:24:22 PM

> 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/1Thanks Andrew, this message made me feel better and I appreciate youasking why I felt that way.My analysis of why is this:   First, know that I was already feelingbad at not being able to figure out the program's error and by thetime I come here, I'm fustrated.  This forum gives me hope.I know this is an informal way of online communication (forums in anycase) but if you were to compare, say the style of the SSCCE's webpage (the one you linked) and what you posted..they essentially saythe same thing...but in different ways.  The state of 'feeling bad'existed in both cases, but the SSCCE's webpage I enjoyed reading and Iwalked away from it feeling ok about myself.  If you want specificexamples, I can go into it...but in general that's it in a nutshell.I understand you were trying to help now.  Thank you.  :)
0
Reply Taria 10/2/2007 9:48:04 AM

14 Replies
78 Views

(page loaded in 0.212 seconds)

Similiar Articles:


















7/18/2012 1:08:16 AM


Reply: