Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 21 of 21

Thread: Problem: cannot find symbol

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem: cannot find symbol

    Hello everyone, first off, I wish to state that I am new to these forums. With that said, if the problem I am about to pose could have been handled in a different section, I do apologize, for I tired to find an appropriate place to pose the issue. Having that out of the way, allow me to me to give everyone a back story.

    To start, the project I am doing is for a class, where I am to enter several inputs(Strings) and have them printed out with a ".txt" extension. Here's my code for visualization:

    package ticket;

    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
    import java.util.logging.Logger;
    import java.util.logging.Level;


    /**
    *
    * @author neilganti
    */
    public class FileTicketAsText {

    private static String file;

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    Scanner scan = new Scanner(System.in);

    String name = getName(scan, " Name");
    String symbol = getSymbol(scan, " Symbol ");
    String title = getTitle(scan, "Title");
    String summary = getSummary(scan, " Summary ");
    String question = getQuestion(scan, " Question");
    String answer = getAnswer(scan, " Answer");
    String nameFile = file + "txt";
    FileWriter outputStream = null;
    String word = null;
    try {
    outputStream = new FileWriter(nameFile);
    BufferedWriter out = new BufferedWriter(outputStream);
    out.write(word + "/n");
    out.close();

    } catch (IOException ex){
    Logger.getLogger(Main.class.getName().log(Level.SE VERE,null,ex));

    }




    }

    private static String getName(Scanner scan, String string) {
    System.out.print(string + "?");
    return scan.nextLine();
    }

    private static String getSymbol(Scanner scan, String string) {
    System.out.print(string + "?");
    return scan.nextLine();


    }

    private static String getSummary(Scanner scan, String string) {
    System.out.print(string + "?");
    return scan.nextLine();
    }

    private static String getQuestion(Scanner scan, String string) {
    System.out.print(string + "?");
    return scan.nextLine();
    }

    private static String getAnswer(Scanner scan, String string) {
    System.out.println(string + "?");
    return scan.nextLine();
    }

    private static String getTitle(Scanner scan, String string) {
    System.out.print(string + "?");
    return scan.nextLine();
    }


    }



    The major issue deals with the line, "Logger.getLogger(Main.class.getName().log(Level.S EVERE,null,ex));". According to NetBeans my JDK, it's stating it cannot find a symbol. Now, after doing research I found it might have to due with either the name of the class being misspelled or undefined? I do not think it is the former observation, given I believe the class is spelled right. However, I am perplexed to say the least as to how to resolve this error.

    All in all, I thank everyone very much for listening to me.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem: cannot find symbol

    For future reference, please wrap your code in the code tags described in the forum rules.

    Break down the nested calls on that line...
    Class cl = Main.class;
    String name = cl.getName();
    //and so one

    you will see when you do so that you are making a call to a log method on the String instance...if you browser through the API for String you should see this method does not exist (in shorter terms, it looks like you may have a misplaced parenthesis - you want to call log on the Logger, not the parameter you pass to get the Logger)

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    Hello, everyone. I tired implementing the solution posted above, but it is not working. The error for "Logger" is in fact worse, with my JDK giving me a more serious error, compared to the simple one. All in all, I'm confused and such am trying not to panic.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    it is not working
    Please post the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem: cannot find symbol

    Quote Originally Posted by ganti91 View Post
    Hello, everyone. I tired implementing the solution posted above, but it is not working. The error for "Logger" is in fact worse, with my JDK giving me a more serious error, compared to the simple one. All in all, I'm confused and such am trying not to panic.
    Please post the full error and updated code. The above wasn't necessarily a solution, but a path to a solution through clarfication

  6. #6
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    Here's the error:

     
     Name? Neil Ganti
     Symbol ? AIG
    Title? Hello World
     Summary ? Standard programming project
     Question? How does it work?
     Answer?
    It processes through main and prints message.
    BUILD SUCCESSFUL (total time: 34 seconds)

    The code is suppose to be the following:



    Name? Neil Ganti
     Symbol ? AIG
    Title? Hello World
     Summary ? Standard programming project
     Question? How does it work?
     Answer?
    It processes through main and prints message.
     
    TicketAIG.txt has been successfully filled.


    Hopefully, that gives a better description of the problem

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    Are you asking about a logic problem with your code?
    What you posted is not an error message.

    Can you explain what the problem is with the program? What is wrong with what it prints out?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    It is in fact a logic error. What's wrong with the program, is that it is supposed to prompt the user to enter information as I had described above and such writes the "ticket" (just like the first code block), but along with doing so the program also a file name, named "Ticket" with the symbol extention of ."txt" (Hence, describing the second code block to which it is suppose to look like).

    However, the weird part is that there is a syntax error with the following segment:
    Logger.getLogger(Main.class.getName().log(Level.SEVERE, null, ex));

    It proclaims it cannot find the symbol.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    It proclaims it cannot find the symbol.
    That sounds like a compiler error.

    Please copy full text of the compiler's error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    When you mean compiler error, you mean this?:


    Name? Craig Delancey
     Symbol ? AIG
    Title? Hello World
     Summary ? Starter program
     Question? Is it easy.
     Answer?
    Yes it is.
    BUILD SUCCESSFUL (total time: 24 seconds)

    There's no red messages nor anything, it's just this as the output.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    See post #9 for a sample compiler error message posted inside of code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    Okay, so it's this

     
    cannot find symbol
     
    symbol: method log(java.util.logging,Level<nulltype>.java.io.IOEXCEPTION)
     
    location: class java.lang.String

    This is the explanation provided by Netbeans My JDK and why the error exists. Hopefully, this suffices

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    What is the symbol that the compiler can not find?
    In post #9 the symbol not found is: var. It is clearly marked with a ^ beneath it.

    The message posted in post #12 does not have a ^ marking the symbol.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    Perhaps the symbol is the following:


     
    Method log.java.(util.logging.Level,<nulltype>.java.io.IOEXCEPTION)
               ^

    The error netbeans has described as a red symbol with an exclamation point. From there upon highlighting, it presents the same information I had presented earlier.

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    What is the symbol in the error message? Try compiling the source with the javac command to get the compiler's error message.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    How do I compile the source with the Javac command? I'm sorry to say, but I'm having trouble understanding you?

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    Open a command prompt window, enter:
    javac <SOURCEFILENAME>.java

    See the tutorial:
    http://docs.oracle.com/javase/tutori...ava/win32.html

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    I have a mac, so it's terminal I believe. That said, I entered "ls" to bring up everything.

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    Sorry, I have no idea how to use a mac or your IDE.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem: cannot find symbol

    So, how do I go about compiling my project at the source?

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem: cannot find symbol

    I use the javac command on windows to compile my java programs. The javac command comes with the JDK.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. cannot find symbol
    By lanpan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2012, 08:13 AM
  2. Cannot find symbol
    By waarten in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 03:15 PM
  3. Cannot find symbol
    By BadgerWatch in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 6th, 2011, 11:25 PM
  4. Cannot find Symbol?
    By defmetalhead in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 5th, 2011, 08:48 AM
  5. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM