/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Cannot find symbol error

Can anyone tell me how to resolve the following compile-time error?

[QUOTE]

TestUserInterface.java:5: cannot find symbol
symbol: class UserInterface
location: class projects.web.TestUserInterface
UserInterface ui = new UserInterface();

[/QUOTE]

I have two classes: UserInterface and TestUserInterface. Both are in the same package.

To compile and run them I use the following cmds respectively:

[CODE]javac -d ..classes projectswebTestUserInterface.java[/CODE]
[CODE]java -cp ..classes projects.web.TestUserInterface[/CODE]

Following is the code for both classes:

[CODE]package projects.web;

import java.awt.*;
import javax.swing.*;

public class UserInterface extends JFrame{

JPanel menuPanel = new JPanel();
JPanel contentPanel = new JPanel();
JPanel selectionPanel = new JPanel();

JButton save = new JButton(“Save”);
JButton addFiles = new JButton(“Add”);

public UserInterface(){
super(“File Upload”);
setSize(500, 500);

menuPanel.add(addFiles);
selectionPanel.add(save);

setLayout(new BorderLayout());
add(menuPanel, BorderLayout.NORTH);
add(contentPanel, BorderLayout.CENTER);
add(selectionPanel, BorderLayout.SOUTH);

} // end constructor

} // end UserInterface clas[/CODE]

[CODE]package projects.web;

public class TestUserInterface{
public static void main(String[] args){
UserInterface ui = new UserInterface();
}
} // end TestUserInterface class
[/CODE]

to post a comment
Java

6 Comments(s)

Copy linkTweet thisAlerts:
@chazzyFeb 28.2009 — Did you ever compile UserInterface?
Copy linkTweet thisAlerts:
@Dan0authorFeb 28.2009 — Did you ever compile UserInterface?[/QUOTE]

Yes, I did.

I found the problem; my code creates the interface, but never sets it to visible.

By adding: [CODE]setVisible(true);[/CODE] the code compiles and runs correctly.
Copy linkTweet thisAlerts:
@chazzyMar 01.2009 — while not explcitly setting visible(true) would have caused the UI to render in an odd manner, the real problem based on the javac error you displayed means that the java compiler ouldn't find your other file (UserInterface.class) note that by default, javac places the generated .class files in the current directory. you can change this by using -d to specify to put the .class in ../classes. since your cp only included ../classes anything in . would have been ignored.
Copy linkTweet thisAlerts:
@Dan0authorMar 01.2009 — while not explcitly setting visible(true) would have caused the UI to render in an odd manner, the real problem based on the javac error you displayed means that the java compiler ouldn't find your other file (UserInterface.class) note that by default, javac places the generated .class files in the current directory. you can change this by using -d to specify to put the .class in ../classes. since your cp only included ../classes anything in . would have been ignored.[/QUOTE]

The problem and the apparent solution has been a bit confounding. You're correct that the java compile-time error indicates that the UserInterface.class couldn't be found.

But I compiled both java files with the following cmd, thus putting them both in the same specified directory, which is other than the current directory:
[CODE]
javac -d ..classes projectswebUserInterface.java

javac -d ..classes projectswebTestUserInterface.java
[/CODE]


When I tried to run the class that contained the main method I specified the classpath and called the file with it fullname - ie. referencing its package (projects.web), with:
[CODE]
java -cp ..classes projects.web.TestUserInterface
[/CODE]


The only change I made was to add the setVisible(true) code. Then I re-compiled and ran the compiled class file as shown above.

So, I don't fully understand what the actual problem and solution was. If you or anyone else knows, please let me know. Thanks.
Copy linkTweet thisAlerts:
@chazzyMar 02.2009 — is it at all possible that you thought you compiled the UserInterface class, but didn't? or maybe missed the -d?
Copy linkTweet thisAlerts:
@Dan0authorMar 02.2009 — is it at all possible that you thought you compiled the UserInterface class, but didn't? or maybe missed the -d?[/QUOTE]

I'm 100% sure that I compiled both classes and placed them in the target directory. I first compiled UserInterface and made sure it was in the target directory. Then I compiled TestUserInterface and made sure it too was in the target directory. Only after both class files were compiled and present in the target directory did I try to run the application.
×

Success!

Help @Dan0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...