• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector cannot be private?

 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I`m developing at the moment this class ( a graph containg nodes and edges etc.)

Why is it not possible to declare the global variables as private?
Graph.java:3: modifier private not allowed here

thx for answers
Robert Ploch
[ May 19, 2003: Message edited by: Robert Ploch ]
[ May 19, 2003: Message edited by: Robert Ploch ]
 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why you see that error, but you have to fully qualify Vector or import it. Otherwise, you will see an error complaining about not understanding vector. Use:
import java.util.Vector;
on the top line and see if that helps.
Other points, they're member variables, not globals. Java does not permit global variables. Member variables can, of course, be private. There's nothing illegal in how you've declared them. However, member variables should start with a lower-case letter. Code is communication. By following conventions you communicate effectively!
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation of global variables. I screwed some definitions
I tested your hint, but the compiler (newest version) still posts this error. It doesn`t depend only on the Vector-Class, the compiler is already complaining about the int with the same error.
It also confuses me, because i didn`t do it different than all the times before.
But see yourself
You`ll find the files on:
www.robertploch.de/files/Node.java
www.robertploch.de/files/Edge.java
www.robertploch.de/files/Graph.java
[ May 19, 2003: Message edited by: Robert Ploch ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Nodes and Edges are class names then you cannot also use them as variable names.
To avoid this be sure to follow the Java naming conventions of using lowercase for the initial letter of variable names, and uppercase for classes.
hth,
bear
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, but the variables do have the name`s: Edges & Nodes;
the class`s names are Edge & Node, without 's', so it should`nt come to an error ( i hope )
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is absolutley nothing wrong with using private where you are using it. What version of Java? Using an IDE? Can you compile a program that has nothing except a single private variable?
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think i`ve got the error
i programmed another, still unready file in the same directory as Graph.java
javac compiled everything and only showed some errors in the unready file.
now i`ve deleted the file and some errors in graph.java were born
ok, now bugfixing
thx for helping
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, but the variables do have the name`s: Edges & Nodes; the class`s names are Edge & Node, without 's', so it should`nt come to an error
I strongly recommend that you follow Java Coding Conventions, -- it will make it easier for everyone (including you) to understand your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic