|
-
Oct 1st, 2006, 05:03 AM
#1
Thread Starter
Member
Cannot find symbol
Hello,
I used to do do some VB a while back and now i'm trying to start teaching myself Java. But i'm having a little problem.
I've searched the forums and found a couple of very simple examples. Some whice i can relate to my small knowledge of VB.
A temperature program someone had made:
VB Code:
public class MyApp
{
public static void main ( String[] args )
{
Scanner scan = new Scanner( System.in ) ;
int temp ;
System.out.print( "Enter the temperature: " ) ;
temp = scan.nextInt() ;
System.out.print( "Activity: ") ;
if ( temp >= 80 && temp <= 95 )
{
System.out.println( "Swimming" ) ;
}
else if ( temp > 95 || temp < 20 )
{
System.out.println( "Visit our Shop!" ) ;
}
else if ( temp >= 60 || temp < 80 )
{
System.out.println( "Tennis" ) ;
}
else if ( temp >= 40 || temp < 60 )
{
System.out.println( "Golf" ) ;
}
else if ( temp < 40 )
{
System.out.println( "Skiing" ) ;
}
}
}
I'm pretty sure i've installed the JAVA 1.5 correctly, the file name was "jdk-1_5_0_08-windows-i586-p" and i just used the default install directory and didnt change any options.
I'm not sure what IDE i should be using but i found a free one called iGRASP. Please give your views on this, and weather i should chance to a different one.
Anyway - to the problem.
i get an error consisting of:
---------------------------------------------------------
Temperature.java:1: class MyApp is public, should be declared in a file named MyApp.java
public class MyApp
^
Temperature.java:5: cannot find symbol
symbol : class Scanner
location: class MyApp
Scanner scan = new Scanner( System.in ) ;
^
Temperature.java:5: cannot find symbol
symbol : class Scanner
location: class MyApp
Scanner scan = new Scanner( System.in ) ;
^
3 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
---------------------------------------------------------
From what i can tell from reading other posts about the same thing, i havnt got it installed correctly? is this the case?
Thanks for any help or advice you can give me! Its all greatly appreciated!
Regards
Mathew
-
Oct 1st, 2006, 08:52 AM
#2
Re: Cannot find symbol
In java, public classes must be in a file with the same name (Case sensitive, yes), so you should have saved the class in a file named MyApp.java, and If your IDE didn't tell you that, then it's not a good one
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 1st, 2006, 08:56 AM
#3
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 10th, 2006, 06:35 PM
#4
Lively Member
Re: Cannot find symbol
What ComputerJy said. Also, the "cannot find symbol" errors are because you have not imported Scanner from the java.util package. At the very top of your code, before you define the class, add:
import java.util.Scanner;
So it really has nothing to do with having iGRASP installed incorrectly. Hope taht helps :-)
EDIT: As far as IDEs, I've tried many and really have come to dislike most of them. I tend to think that they are too "busy" such as netbeans. (However if you want to try it, netbeans is available from java.com directly for free). For simple projects I just use Textpad (free download here). For larger projects I use BlueJ, which is also free here. It has a nice visual layout where you can organize your classes that comes in handy without being bogged down by millions of features that you'll never use. JBuilder is more advanced than either of these two and has a bunch of features, but at the same time is easy to manage. It's really all about what you feel comfortable with and the scale of the project that you're working on. The best thing you can do it to try them all out and see for yourself which one you like best.
Last edited by lunchboxtheman; Oct 10th, 2006 at 06:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|