Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Cannot find symbol java error (newbie question)

Reply
Thread Tools

Cannot find symbol java error (newbie question)

 
 
Taria
Guest
Posts: n/a
 
      09-29-2007
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 )

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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      09-29-2007
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.asp...neral/200709/1

 
Reply With Quote
 
 
 
 
Taria
Guest
Posts: n/a
 
      09-29-2007
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

 
Reply With Quote
 
Taria
Guest
Posts: n/a
 
      09-29-2007
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


 
Reply With Quote
 
Taria
Guest
Posts: n/a
 
      09-29-2007
On Sep 29, 12:38 am, Taria <(E-Mail Removed)> 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

 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      09-29-2007
Taria <(E-Mail Removed)> 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 - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-29-2007
On Sat, 29 Sep 2007 02:34:22 -0700, Taria <(E-Mail Removed)> 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 )
>
> 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-29-2007
On Sat, 29 Sep 2007 03:38:34 -0700, Taria <(E-Mail Removed)> 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
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-29-2007
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.asp...neral/200709/1

 
Reply With Quote
 
Taria
Guest
Posts: n/a
 
      09-29-2007
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Encryption Package) error: cannot find symbol symbol: class BaseNCode clusardi2k@aol.com Java 6 08-29-2012 08:33 PM
Java - cannot find symbol nalbertini Java 1 02-12-2011 07:59 PM
javac error when using jar file : cannot find symbol powah Java 5 03-22-2009 12:45 AM
Creating class gives "cannot find symbol" error luch Java 5 10-05-2005 04:13 PM
java:143: cannot find symbol Danny Java 1 05-26-2004 08:46 AM



Advertisments