This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Symbol7 for Class error -- no package used just normal class

 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am novice user of JAVA

Created 2 Class

Shirt.java
ShirtTest.java

in C:\labs folder

Then tried to compile Shirt.java compiled perfect

ShirtTest.java give me Symbol7 for Class

set up environment variables

checked for import

but can not solve error.
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
Please provide more details. We can't understand the problem from the little information you have provided.
 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Installed JDK C:\Program Files\Java\jdk1.6.0_12

Set Environment Variables

As exercise I created 2 classes in given directory

C:\Program Files\Java\jdk1.6.0_12\bin\Labs\SL110\exercises\getstarted

Shirt.java
=====================================
public class Shirt {

public int shirtID = 0; // Default ID for the shirt
public String description = "-description required-"; // default

// The color codes are R=Red, B=Blue, G=Green, U=Unset

public char colorCode = 'U';

public double price = 0.0; // Default price for all shirts

public int quantityInStock = 0; // Default quantity for all shirts

// This method displays the values for an item

public void displayShirtInformation() {

System.out.println("Shirt ID: " + shirtID);
System.out.println("Shirt description:" + description);
System.out.println("Color Code: " + colorCode);
System.out.println("Shirt price: " + price);
System.out.println("Quantity in stock: " + quantityInStock);
} // end of display method
} // end of class



Other class where my main is

ShirtTest.java

import java.Shirt.*;

public class ShirtTest {
public static void main (String args[]) {

Shirt myShirt;
myShirt = new Shirt();

myShirt.displayShirtInformation();
}
}


Now, from CMD prompt try to run both classes

running Shirt.java compile fine and perfect no errors and create Shirt.class

after that compiling ShirtTest.java which give me errors as given below:

ShirtTest.java:4: cannot resolve symbol
symbol : class Shirt
location: class ShirtTest
Shirt myShirt;
^

ShirtTest.java:5: cannot resolve symbol
symbol : class Shirt
location: class ShirtTest
myShirt = new Shirt();
^

Attaching Screeshot for more details

Also, I tried all possible solutions in FAQ, google as well other forums

and this is part of sun training program fundamentals one.



 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File attachment here..
Filename: untitled.bmp
Description:
File size: 661 Kbytes
[Download untitled.bmp] Download Attachment
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cd C:\Program Files\Java\jdk1.6.0_12\bin\Labs\SL110\exercises\getstarted
javac -cp . ShirtTest.java

That's "javac space dash cp space dot space ShirtTest.java" .

The problem is that your CLASSPATH environment variable should be not set to anything, but you have it set to something, and that something doesn't include "." (dot), which stands for the current directory, whatever it is.
 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried given and it give me given message

C:\Program Files\Java\jdk1.6.0_12\bin\Labs\SL110\exercises\getstarted>javac -cp
. ShirtTest.java
javac: invalid flag: -cp
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are us
ed
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-help Print a synopsis of standard options


C:\Program Files\Java\jdk1.6.0_12\bin\Labs\SL110\exercises\getstarted>


After that also updated CLASSPATH in environment variables but same behavior please advice, appreciate your reply Ernest Friedman & Campbell Ritchie..
 
fred rosenberger
lowercase baba
Bartender
Posts: 12090
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after you updated your classpath, did you open a new command window? One that is already open will not pick up your changes.
 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\/

SUCCESS !!

also when I execute ShirtTest

i.e. C:.. > javac ShirtTest

It give me classnotfoundexception so I replaced command with javac -cp . ShirtTest

but I wonder why to use -cp everytime if someone can explain ..

Thanks
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that, having set up a classpath, you have prevented the java tool from finding the classes is ought to execute.

If you set up the classpath variable yourself, delete it altogether, and see what happens.
If you didn't set it up yourself, edit it to include . for current directory. It can start with .; or end with ;. or have ;.; in the middle, assuming you are using DOS/Windows.

Don't put your work in Program Files; when you open your command prompt write

mkdir java


(or similar) then you can write

cd java

whenever you open a command prompt, and go to wherever your Java work it. That Java folder will be somwhere in documents and settings, where you ought to keep your work.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To execute it use
java ShirtTest

and not javac ShirtTest

 
Jiken Jarecha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell .. understood conceptually

Sri I use java for execution

Working on Sun Trainings .. started with fundamentals

are there any people who doing same?

Also my learning path is

Sun trainings then K&B books targeting SCJP exam

any inputs ? how long it should take considering 3 hours a day avg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic