• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Importing variables interdependent classes

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic