Java Forum / General / October 2007
Cannot find symbol java error (newbie question)
Taria - 29 Sep 2007 10:34 GMT 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
Andrew Thompson - 29 Sep 2007 11:02 GMT 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.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Taria - 29 Sep 2007 11:11 GMT > Sub: Cannot ... (newbie question) > [quoted text clipped - 36 lines] > > 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 - 29 Sep 2007 11:38 GMT 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 - 29 Sep 2007 11:47 GMT > 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 [quoted text clipped - 41 lines] > > -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
Lasse Reichstein Nielsen - 29 Sep 2007 12:01 GMT > 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
 Signature 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.'
Roedy Green - 29 Sep 2007 12:31 GMT >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
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Andrew Thompson - 29 Sep 2007 13:50 GMT >>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.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Roedy Green - 30 Sep 2007 08:46 GMT >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.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Lew - 30 Sep 2007 16:53 GMT "Andrew Thompson":
>> 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. 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.
 Signature Lew
Taria - 02 Oct 2007 10:48 GMT > To Taria. I am not offended, and intended the advice > to help you. [quoted text clipped - 8 lines] > > 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. :)
Roedy Green - 29 Sep 2007 12:12 GMT > import java.util.*; > import java.lang.*; [quoted text clipped - 27 lines] > } > } 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.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Taria - 29 Sep 2007 18:51 GMT > 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. [quoted text clipped - 13 lines] > > - 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
Daniel Pitts - 30 Sep 2007 18:19 GMT > Hello all! > [quoted text clipped - 56 lines] > 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[i].intValue()); /* succeeds */ } } }
Lew - 30 Sep 2007 20:24 GMT > Look at this SSCCE: > [quoted text clipped - 10 lines] > } > } 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.
 Signature Lew
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|