• 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

why won't this compile?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i try to compile this simple skeleton for a start of a program do I get the follwing error:
MyApp.java [21:1] cannot resolve symbol
symbol : constructor MyCode (MyGUI)
location: class MyCode
mc = new MyCode(mg);
why can I not pass MyGui to MyCode?
thanks
Hugh

public class MyApp{

public MyApp(){

MyCode mc = null;
MyGUI mg = new MyGUI();
mc = new MyCode(mg);

}

public static void main(String args[]){
MyApp ma = new MyApp();

}
}

public class MyCode {

private MyGUI mgl;

public MyCode(MyGUI mg) {
mgl=mg;
}
}

public class MyGUI{

private JButton testButton;
private JButton testButton2;
private JPanel panel1;

public MyGUI() {

JFrame f = new JFrame();

testButton = new JButton("Test...");
testButton2 = new JButton("Test2...");

panel1= new JPanel();
panel1.add(testButton);
panel1.add(testButton2);

f.getContentPane().add(panel1);

f.pack();
f.show();

}
}
MyApp.java [21:1] cannot resolve symbol
symbol : constructor MyCode (MyGUI)
location: class MyCode
mc = new MyCode(mg);
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What compiler are you using? The standard Sun compiler won't let you put more than one public class in a single .java file.
 
h slater
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't state this, but it is complied in 3 seperate java files
Hugh
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are your 3 java files correctly named? The files must match the name of the public class they contain. Are they all in the same directory?
Are you importing swing in MyGUI.java ?
Don't forget the mandatory order:
package (optional)
import (optional, but you do need swing)
public class
 
h slater
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes all class names correspond to the file names

the class MyGUI and MyCode complile without any problem.
It is only when I compile MyApp that I have the error message shown at the end of the first post.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try another thing, I notice that your MyGUI class name has GUI in capital letter. Just make sure that the filename of this class is MyGUI.java and not MyGui.java
Let us known if it works or not !!
Yves
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what order are you compiling these files?
It looks to me like MyGUI.class must exist before MyCode.java will compile, and MyApp.java requires both MyCode.class and MyGUI.class before it will compile.
So try this:
javac MyGUI.java
javac MyCode.java
javac MyApp.java
I did it with your code (after adding "import javax.swing.*;" to MyGUI.java), and it compiled and ran just fine.

Now, if you REALLY wanna have fun, try putting a reference to MyApp in MyGUI.java!
PCS
[ November 22, 2002: Message edited by: Philip Shanks ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For me, it doesn't matter what order I compile in. In fact, I can just say
javac MyApp.java
and it will automatically compile the other two files for me.
One thing to watch out for: if you have a CLASSPATH defined, you must include "." (the current directory) somewhere in it.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the point was to localize the problem.

If you don't include the
import javax.swing.*;
statement, the MyGUI class won't compile.

If the MyGUI doesn't compile, MyApp won't compile either. But if someone compiles them all at once, they may not realize where the problem lies.
 
h slater
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mystery solved....
I am using Sun One Studio (Forte) and I had several directories "mounted".
In one of the other directories was another class called MyCode which did not have the same constructor arguments.
The IDE was attempting to compile the code with this class and not the one in the directort that I ws working in. Something to look out for, for the future!
many thanks for all the suggestions
Hugh
 
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic