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.
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...
Code :
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)
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.
Re: Problem: cannot find symbol
Please post the full text of the error messages.
Re: Problem: cannot find symbol
Quote:
Originally Posted by
ganti91
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
Re: Problem: cannot find symbol
Here's the error:
Code :
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:
Code :
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
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?
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:
Code :
Logger.getLogger(Main.class.getName().log(Level.SEVERE, null, ex));
It proclaims it cannot find the symbol.
Re: Problem: cannot find symbol
Quote:
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:
Code :
TestSorts.java:138: cannot find symbol
symbol : variable var
location: class TestSorts
var = 2;
^
Re: Problem: cannot find symbol
When you mean compiler error, you mean this?:
Code :
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.
Re: Problem: cannot find symbol
See post #9 for a sample compiler error message posted inside of code tags.
Re: Problem: cannot find symbol
Okay, so it's this
Code :
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
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.
Re: Problem: cannot find symbol
Perhaps the symbol is the following:
Code :
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.
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.
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?
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.
Re: Problem: cannot find symbol
I have a mac, so it's terminal I believe. That said, I entered "ls" to bring up everything.
Re: Problem: cannot find symbol
Sorry, I have no idea how to use a mac or your IDE.
Re: Problem: cannot find symbol
So, how do I go about compiling my project at the source?
Re: Problem: cannot find symbol
I use the javac command on windows to compile my java programs. The javac command comes with the JDK.