Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing variables interdependent classes

 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im tryin to use a variable of class x in class y, and vice versa. they are in the same package. Now the problem is i cacnot compile claas x as it says variable not found and niether class y as it gives the same error.

My problem is : i have 2 class x which is the GUI and classs Y which does the prser of the file and gives result. Class Y needs the name of the file which the user accepts through JFIleChooser, and does the work. Now class X calls the method of class y to get results. Now i cant compile class y as it needs the variable from class X and neither can class X as it needs the method from class Y.

Please advice

[ EJFH: Removed "URGENT". All questions are equally important here. ]
[ October 17, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile them both at once:

javac X.java Y.java
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i tried doin it but it didnt work....it stil gives the error that variable in file x is missin

please advice
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post your code? (Be sure to use the UBB CODE tags to preserve your formatting. There are buttons below the message editing box.) I suspect there is something missing rather than just a problem with compiling. From my experience, the Java compiler can resolve such circular references if they are done correctly.
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the supporting class...it needs to have a String variable
Sting filename which it uses to do some analysis

public class analysis
{

FileReader rd;
FileWriter phy;
FileWriter gen;
BufferedReader brd;

JFileChooser fc;
File file;

String fileName="full1.txt";

public void methodAnalysis()
{
try
{
rd=new FileReader(fileName);
brd = new BufferedReader(rd);

phy =new FileWriter("physical.txt");
gen =new FileWriter("genetic.txt");

}
catch(FileNotFoundException e3)
{
System.out.println(e3.toString());
//System.exit(0);
}

catch(IOException e4)
{
System.out.println(e4.toString());
//System.exit(0);
}

.....................................................

}

This class has the main and the gui....it accepts the file name through
Jfilechooser and then has to call the above analysis class to generate 2 files....and then again calls its method to work on those 2 files...

public void actionPerformed(ActionEvent e)
{

// Analysis of the loaded file and display output
if(e.getSource()== headerB1)
{
anaD = new analysis();
// this belongs to the class analysis
anaD.methodAnalysis();
// this belongs to this class
methodWrite();

}
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohoh i forgot to add on that in the above code snippet...
in the analysis class String filename is also defined...that is to be overlooked as it has been already declared in the other class and the analysis class has to get it...my code wasnt runnin so i had added that piece...

Thanx
abhishek
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx guys...finally i got it right(through inner class)...though i m yet to figure what went wrong in the above way...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic