Java error: cannot find symbol - method hasNext?
The API is your best friend. More important than the text book or your .... teacher! :P If you look at the Java API, you will see that the class FileReader does not have a method called hasNext. My Java is rusty, but I think hasNext() is in the Iterator interface. It has nothing to do with the FileReader. Also I think you're reading the file wrong. You're supposed to pass an instance of FileReader to the BufferedReader's constructor. This is how you would read in a file: http://www.exampledepot.com/egs/java.io/ReadLinesFromFile.html It seems like you have a file of numbers and you're trying to read them. You need to use the readLine() method of the BufferedReader class to read an entire line. But before you do that, do you know how you are delimiting the numbers? Spaces? Commas? Hyphens? Then you could use the split method of the String class to split the numbers up into an array by their delimiter. Once the numbers are in an array you can work with them. Once you do all that the method can get pretty large. As a rule of thumb, you should never have more than 20-25 of code lines per method. More than that, and it's probably bad design. If you have too many lines, decompose some things into other methods. EDIT: Try Paul's method! I didn't think of the Scanner. Scanner has a nextInt() method. Should be much easier for your purposes :-)
What are common reasons for the Java "cannot find symbol" error?
the simple reason is g#*@! hagfh%$%$ bdf$#$.what happened?you didn't get it, right?that is because you have never seen the things I typed, before. English dictionary has none of these words defined so you don't get is. simple.Now consider yourself a compiler and these words as lines of codes. I hope you get it now.... :P
Java error: cannot find symbol IoException?
I am enrolled in a Java class, we are working on Writing and Reading information to/from a file. I am having issues with my WriteData.java code. I receive the following error: WriteData.java:5: error: cannot find symbol public static void main(String[] args) throws IoException { ^ symbol: class IoException location: class WriteData 1 error My code is as follows: public class WriteData { public static void main(String[] args) throws IoException { java.io.File file = new java.io.File("scores.txt"); if (file.exists()) { System.out.println("File already exists"); System.exit(1); } // create a file java.io.PrintWriter output = new java.io.PrintWriter(file); // write formatted output to the file output.print("John T Smith "); output.println(90); output.print("Eric K Jones "); output.println(85); // close the file output.close(); } } Any help will be appreciated. I am not understanding WHY the IoException is not recognized.
Java Error...Cannot find symbol - class?
JPanel is in javax.swing You need to add: import javax.swing.JPanel; You could just use: import javax.swing.*;
Cannot find symbol class Pause? Java 5?
I can't find a way to call the Pause method and insert the symbol class to make this work. I have to input that I'm looking for a number between 1 and 20 and I have to make the program wait five seconds before giving the number. It's the Pause wait, instantiating and calling the method that's messing me up. Can someone help please?
The Java program shows an error "cannot find symbol", what does that mean?
The code appears to be correct. Please check that the file name is Differrence.java (with a double ‘r’). If you're declaring a class as public, then the file that contains that class should have the same name as that of the class. Maybe that's a spelling mistake in your case, and the file name doesn't exactly match the class name.If that's not the case, then please post the complete error that is being displayed while compiling the program.
LinkedList in java cannot find symbol?
i dont know how to solve this error please help me import java.io.*; public class Lk { public static void main(String[] args) { LinkedList names = new LinkedList(); names.add("A"); names.add("B"); names.add("C"); names.add("D"); names.add("E"); names.add("F"); names.addfirst("Q"); names.addlast("S"); System.out.println("Value of LinkedList:" + names); names.remove(2); names.remove(1); System.out.println(); System.out.print("The value of LinkedList:" + names); } } error : C:\mywork\LinkedList\Lk.java:7: cannot find symbol symbol : class LinkedList location: class Lk LinkedList names = new LinkedList(); ^ C:\mywork\LinkedList\Lk.java:7: cannot find symbol symbol : class LinkedList location: class Lk LinkedList names = new LinkedList(); ^ 2 errors
Java error:cannot find symbol variable output label?
I have tried many things, and since I'm new to java I really don't know what to try. Here is my code: /* Chapter 3: The Body Mass Index Calculator Programmer: J. Starks Date: October 20, 2007 Filename: BodyMassApplet.java Purpose: This project calculates the body mass index based on a person's height and weight. */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class BodyMassApplet extends Applet implements ActionListener { //declare variables Image logo; //declare an Image object int inches, pounds; double meters, kilograms, index; //construct components Label companyLabel = new Label("THE SUN FITNESS CENTER BODY MASS INDEX CALCULATOR"); Label heightLabel = new Label("Enter your height to the nearest inch: "); TextField heightField = new TextField(10); Label weightLabel = new Label("Enter your weight to the nearest pound: "); TextField weightField = new TextField(10); Button calcButton = new Button("Calculate"); Label outputlabel = new Label("Click the Calculate button to see your body mass index."); public void init() { setForeground(Color.red); add(companyLabel); add(heightLabel); add(heightField); add(weightLabel); add(weightField); add(calcButton); calcButton.addActionListener(this); add(outputLabel); logo = getImage(getDocumentBase(), "logo.gif"); } public void actionPerformed(ActionEvent e) { inches = Integer.parseInt(heightField.getText()); pounds = Integer.parseInt(weightField.getText()); meters = inches / 39.36; kilograms = pounds / 2.2; index = kilograms / Math.pow(meters,2); outputLabel.setText("YOUR BODY MASS INDEX IS " + Math.round(index) + "."); } public void paint(Graphics g) { } } and the error is: F:\BodyMassApplet.java:40: cannot find symbol symbol : variable outputLabel location: class BodyMassApplet add(outputLabel); ^ F:\BodyMassApplet.java:52: cannot find symbol symbol : variable outputLabel location: class BodyMassApplet outputLabel.setText("YOUR BODY MASS INDEX IS " + Math.round(index) + "."); ^ 2 errors
Cannot find symbol error in Java program? help please!?
this error keeps showing up when i compile my program: pg2a.java:23: cannot find symbol symbol : method substring(java.lang.String) location: class java.lang.String String character = input.charAt(0, input.substring(" ")); can anyone help me figure out whats wrong with it? It points to the period between input and substring. Here is the rest of the program: import java.util.Scanner; public class pg2a { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String userName; System.out.print("Enter your name:"); userName = keyboard.next(); System.out.println("Choose a character: Pikachu, Charmander, Squirtle, or Bulbasaur. Capitaliza the first letter. Enter a level between 1 and 15."); String input = keyboard.next(); String character = input.charAt(0, input.substring(" ")); int level = input.indexOf(" "); System.out.println("Added level " + level + character + " for " + userName); boolean change = false; if (level > 1 || level < 15) { System.out.println("Invalid level!"); change = true; } } }
Why am I getting "cannot find symbol"?
Thank you for asking me to answer .Why haven't you search a little bit on Google? Java compile error: cannot find symbolAnyway , I pasted your code in order to compile it and the error was: input cannot be resolvedWhat you have to do is : well , I tell to my computer : y = input.nextInt();But it doesn't know who input is. So you define it :Scanner input = new Scanner( System.in );After that, you compile it again , and you will be excited that this works!As an advice , when you are stack in a problem , ask on programming forums , on stackoverflow for example, because there you will have more chances to receive an answer. Happy coding !