• Post Reply Bookmark Topic Watch Topic
  • New Topic

Symbol cannot be solved  RSS feed

 
jred ken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got an error "Symbol cannot be solved" when i compile it. whats that mean?
im using j2sdk1.4.2_05.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means you are using a name of a variable or class that doesn't exist or cannot be found at the place you are using it.

Note that the compiler tells you, in the error message, exactly what it cannot find and in which line of your source code the error happens. Look at the relevant line in your source code and figure out what's wrong there.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is often the result of a typo... you mis-spell a variable name somewhere, or change the case... i.e.

numFriends becomes numFreinds or

thisIsALongVariable becomes thisisALongVariable.
 
jred ken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the source code from the tutorial website i use.

public class HelloWorld extends JFrame {

public HelloWorld()
{
super();
this.setSize(300, 200);
this.getContentPane().setLayout(null);
this.add(getJLabel(), null);
this.add(getJTextField(), null);
this.add(getJButton(), null);
this.setTitle("HelloWorld");
}

private javax.swing.JLabel getJLabel() {
if(jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setBounds(34, 49, 53, 18);
jLabel.setText("Name:");
}
return jLabel;
}


private javax.swing.JTextField getJTextField() {
if(jTextField == null) {
jTextField = new javax.swing.JTextField();
jTextField.setBounds(96, 49, 160, 20);
}
return jTextField;
}

private javax.swing.JButton getJButton() {
if(jButton == null) {
jButton = new javax.swing.JButton();
jButton.setBounds(103, 110, 71, 27);
jButton.setText("OK");
}
return jButton;
}

public static void main(String[] args)
{
HelloWorld w = new HelloWorld();
w.setVisible(true);
}
}

this is the error
java: 17: Symbol cannot be solved.
Symbol: Variable jLabel
place: The class jLabel of HelloWorld = new javax.swing.JButton ();

also jButton and jTextField same error.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nowhere do you declare the variables named "jLabel" or "jButton" or "jTextField", so that's why the compiler is complaining. You can't use a variable without declaring it -- explicitly stating its data type and scope.

You could put something like this, just inside the body of the class, outside of any method:

javax.swing.JLabel jLabel;
javax.swing.JButton jButton;
javax.swing.JTextField jTextField;

and this would declare the three variables as instance member variables.
 
jred ken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill

Thank you it is compile but when i run it there`s an exception error

Exception in thread "main" java.lang.Error: Do not use HelloWorld.add() use Hell
oWorld.getContentPane().add() instead
at javax.swing.JFrame.createRootPaneException(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at HelloWorld.<init>(HelloWorld.java:15)
at HelloWorld.main(HelloWorld.java:50)
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a very user-friendly error message, as it tells you precisely what to do to get rid of it.
 
jred ken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer

Can you help me? i dont know how to fix that very friendly error. i am very new in java.

thanks
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this.add(getJLabel(), null);
this.add(getJTextField(), null);
this.add(getJButton(), null);


Changing this to:




might help.
 
jred ken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai

Thank you very much it runs smoothly.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!