File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes variable not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "variable not found" Watch "variable not found" New topic
Author

variable not found

Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
hi to all...iam very new in using Jbuilder i have a small question that if i have built two classes and i have defined a string in the first class that contains a user input file..then in the second class i need to calculate the length of that string(the user input file) so i said
Line.lenght() but i had thr error:
Error #: 300 : variable Line not found in class project_two.Calculate_Padding_bits at line 19, column 10
what i shall do ..by the way the two classes is on the same Package and even that i tried to make import for the first class in the second one...plz help me on this problem....
Mohammad
Jeremy Tartaglia
Ranch Hand

Joined: Mar 11, 2004
Posts: 62
My guess is that you're not taking into account that you have two classes. The variable is only defined in your first class, not the second. Like this:



In Class2, x is not defined. So the compiler will question why you're using it. If you need to access an attribute in another class, there are two accepted ways: direct access, and accessor methods. Direct access seems to be frowned on, but for low security data, often modified data, or simple projects, I don't see it as a problem. This method is to make the attribute protected (accessible by subclasses), package, or public, and just access them through an object:



With Object Oriented programming, a new idea was created: accessor methods. The idea behind this is to limit all attributes to private, and write functions to view or modify the data:



This has become the most accepted way to deal with attributes, as you can limit a variable to read only, write-only, or read-write depending on the object itself. It also allows you to perform the modification at an appropriate time, to avoid crashes.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Go with the second approach i.e using acessors and mutators. the direct access of variables break encapsulation.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
thanx a lot for this useful reply...i want to ask another small question that :
if i have defined in my code :
static int length;
then i need to convert and represent this integer into 64-bit big indean what shall i do in java ...can i find any function to do this??
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Mohammad Ahmad:
thanx a lot for this useful reply...i want to ask another small question that :
if i have defined in my code :
static int length;
then i need to convert and represent this integer into 64-bit big indean what shall i do in java ...can i find any function to do this??


MULTIPOST


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable not found
 
Similar Threads
2 Public classes in one file
References between classes
Hoiw to document member variables of a class?
How do i connect two loops together?
Input/Output Question...