Jump to content
  • Advertisement
Sign in to follow this  
silverphyre673

Starting java... cannot find symbol error.

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I'm finally taking a programming class after three years. My language has been C++ up until now, and they are having me learn java. I don't have a textbook or anything like that (they haven't been real good like that - the classes I had to take to qualify for this one had us using turbo C 4.5, which I believe is outdated). Anyways, I'm trying to learn a bit of the language before I actually start, and I'm trying to just get some console input working. I got the obligatory "Hello, World" out of the way with a minimum of fuss, but now I just want to try input, and it's being finnicky. I tried this:
class YourName
{
    public static void main(String [] args)
    {
        String name;
        System.out.println("Enter your name: ");
        name = System.in.readLine();
        System.out.print("Hello, ");
        System.out.print(name);
    }
}
But I get an error about System.in.readLine() "cannot find symbol". This is the java 5.0 (I guess) JDK that I just downloaded off Sun's website. I set the PATH variable to point to the correct directory, and as I said, the "Hello, World" program worked fine. So just to get me started, how should I correct this to make it work? Or is it something more insidious, a problem of environment variables not being set right? By the way, I'm using command line to "compile" and run the code (javac and java). Thanks a million.

Share this post


Link to post
Share on other sites
Advertisement
try this... I've always used this as a standard way for getting console input. Hope it helps :)


import java.io.*;

class Console_Practice
{
public static void main(String [] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = "";
System.out.print("Enter your name: ");
name = br.readLine();
System.out.print("Hello, ");
System.out.println(name);
}
}


Share this post


Link to post
Share on other sites
Java's System.in does not support readLine(). One way of obtaining this functionality is to wrap it with a BufferedReader:

import java.io.*;
...
BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
someString = inReader.readLine();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!