One more java compile error?

October 1st, 2007 at 05:27pm Under Forum

One more java compile error?
Hey all, I’m working on a program that allows users to input how many movies they can rent and asks if the video is a new release, however when I compile I get just ONE error in the programming. It says it cannot find the symbol EVEN THOUGH I imported my libraries necessary. Is the command I’m using not a valid command? or is the way I’m executing it in my script…?

the error is:
cannot find symbol — method charAt(int)
location: class java.util.Scanner

Here is my source:
import java.util.*;
import java.text.*;
import java.awt.*;
import javax.swing.*;
public class Test
{
public static void main(String[] args)
{
int num;
char answer;
String s;
double total;
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

Scanner input = new Scanner(System.in);

JOptionPane.showInputDialog(“How man videos are being rented?”);
num=Integer.parseInt(s);
for (int i=0; i {
JOptionPane.showInputDialog("Is Video #"+i+1+"is a current release?");
answer = input.chartAt(0);
if(answer=='y' || answer=='Y')
total = total+3.50;
else
total = total+2.50;
}
JOptionPane.showInputDialog("Your total is: "+total);
}
}

By the way, thank you all for answering my last question, the best answer will be chosen.

Also, again, I'm not looking for an ANSWER just a point in the right direction.

Thanks!
I just changed it to CharAt(int) instead of ChartAt(int) got rid of the t and it still does not compile

Best answer:

you typed “chartAt(int)”, get rid of that extra t.

By Barcode Scanner 2 comments

java error……….???

September 30th, 2007 at 10:06am Under Forum

java error……….???
This my code but i always keep getting a ‘cannot resolve symbol’ error on my import java.util.Scanner; anyone know why?

import java.util.Scanner;

public class Population{

public static void main(String [] args){
Scanner reader = new Scanner(System.in);
int initialPop;
double growthRate;
int hours;
double popGrowth;
int totalPop = 0;
int totalhours;

System.out.print(“Enter the initial number of organisms:”);
initialPop = reader.nextInt();
System.out.print(“Enter the rate growth:”);
growthRate = reader.nextDouble();
System.out.print(“Enter the number of hours population grows:”);
hours = reader.nextInt();
System.out.println(“Enter the number of hours the growth rate achieves:”);
totalhours = reader.nextInt();
System.out.println(“At this rate the population will be:”);

for(int hourscalc = 0;hours>0; hourscalc+=2){
totalPop =(int)(initialPop * growthRate);

System.out.println(totalPop);
}
}
}
i am also geting the same error on Scanner reader, do i have to make a Scanner class oath, and if so how do i make it?

Best answer:

when you compile make sure you use javac and also make sure you set the class path to the compiler

By Barcode Scanner 1 comment

I just got help with trying to compile a jave program but now I have a new error. Can anyone help me out.?

September 23rd, 2007 at 02:49am Under Forum

I just got help with trying to compile a jave program but now I have a new error. Can anyone help me out.?
This is what I am trying to compile.

import java.util.Scanner;
public class Program2
{
public static void main (String[] args)
{
Scanner scan=new Scanner( System.in );
//declare and initalize a new scanner object
int num, hours, minutes, seconds;
//int x = 9733;

System.out.println(“Enter the number of seconds:9733″);

num= scan.nextlnt();
//plug entered number into num variable
hours= num/3600;
//divide entered number by 3600 to get hours
minutes= (num%3600)/60;
//take the remainder of num/3600 and divide it by 60 to get minutes
seconds= (num%3600)%60;
//take whats left for the seconds

System.out.println(num + “s=” + hours + “h,” + minutes + “m, and” + seconds +
“s”);

}
}

This is the error I am getting.

1 error

javac Program2.java
Program2.java:13: cannot find symbol
symbol : method nextlnt()
location: class java.util.Scanner
num= scan.nextlnt();
^

Best answer:

your scan.nextlnt is using the letter L so your spelling scan.Lnt not scan.Int.

Switch your L to and I and it compiles.

By Barcode Scanner Add comment

Hello Peeps i got a (95 Z28 LT1 A4) anyways i got these error messages that appear on my gauge cluster so i?

September 8th, 2007 at 10:33pm Under Forum

Hello Peeps i got a (95 Z28 LT1 A4) anyways i got these error messages that appear on my gauge cluster so i?
was thinking of buying a Scanner to plug into the port and see what the problems are (by the way the error messages that are showing up are the Airbag Light,Coolant red box symbol,Service Engine Soon Light) since everything for the last 20 years has been computer aided i though i would plug into the port on my 95 Z28 and see what i need to fix is there any particular scanner that i should get?

Best answer:

Yes. You will have to buy for that specific model and year. Standardized scanners did not start until the 96 model year. It may be cheaper to take it to a dealer than to buy the unit.

By Barcode Scanner Add comment

after i compiled the program code for Java, an error message appeared.. need Help..?

June 29th, 2007 at 09:02am Under Forum

after i compiled the program code for Java, an error message appeared.. need Help..?
“cannot resolve symbol class Scanner”. for the program to run, what should i do?

Best answer:

You forgot to import java.util.* or some other library that has Scanner (I think its the util library).

By Barcode Scanner Add comment

Java error: cannot find symbol – method hasNext?

February 10th, 2007 at 04:06pm Under Forum

Java error: cannot find symbol – method hasNext?
Hopefully somebody can help me out with this I did something wrong.

Code:

import java.io.*;
import java.util.Scanner;
public class DataSet
{
public static void main(String args[]) throws IOException
{
FileReader inFileReader = new FileReader(“c://testdata.txt”);
double NextDouble;
double x;
double y;

while(inFileReader.hasNext())
{
NextDouble = inFileReader.Next();
x = 0.0 + NextDouble;
y = 1.0 * NextDouble;
}

System.out.println(“The sum of all numbers is ” + x + “.”);
System.out.println(“The product of all numbers is ” + y + “.”);
}
}

//
I’m not really sure what I did wrong here but BlueJ is yelling at me.

Best answer:

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:
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 :-)

By Barcode Scanner 3 comments

getting error message "cannot find symbol – variable radius" java?

January 21st, 2007 at 09:15am Under Forum

getting error message “cannot find symbol – variable radius” java?
here is what i have:

public static void main (String [] args)
{
double value = 0;
double radius;
Scanner keyboard = new Scanner (System.in);

System.out.print(“Enter the radius of the circle: “);
radius = keyboard.nextDouble();
value = Area();
System.out.println(“The area of the circle is ” + value);
}

public static double Area()
{
return Math.PI * Math.pow(2, radius);
}

how can i help it find the variable radius?

Best answer:

In your main() method, you defined a variable called “radius”. This is a local variable, and is not visible outside this method. But you’re trying to use it in your Area() method.

You probably want to pass the radius value to your Area() method as a parameter.

By Barcode Scanner 1 comment

cannot find symbol java error?

November 25th, 2006 at 10:54pm Under Forum

cannot find symbol java error?
Hello, I am very new to learning java and am trying to learn by writing a program which I will slowly evolve into a more meaningful program.
I am currently having a problem progressing as I am getting the error:
cannot find symbol
symbol : class player
location: class test

I have 2 java files, both on my desktop the first is called player.java (this compiles to player.class with no problems)
player.java
—————
public class player{

int num;

void player(){
num = 0;
}

public void Add_one(){
num++;
}

public int getnum(){
return num;
}

public void setnum(int x){
num = x;
}
}
===========
The second is test.java this is the file which when I try to compile(using javac ) I get the error.
test.java
————
import java.util.Scanner;
public class test{

public static void main(String[] args){

Scanner my_in = new Scanner(System.in);
player one = new player();
int result = my_in.nextInt();
one.setnum(result);
one.Add_one();
one.Add_one();
result = one.getnum();
System.out.print(result);
}
}

===========
When I google the problem I find the main reasons for it are that the class file is not imported (I don’t think this matters as the files are both on my desktop)

Thanks in advance for any help

Best answer:

= my_in, yeah

By Barcode Scanner 2 comments

I keep getting the same error in my java program so I can't run it. It says symbol errors. Can anyone help me?

August 2nd, 2006 at 11:59am Under Forum

I keep getting the same error in my java program so I can’t run it. It says symbol errors. Can anyone help me?
Im not sure what symbol errors mean but can someone help me out here.

import java.util.Scanner;
public class Diamond{
public static void main(String[] args){
int height;
height = 6;
for (int i=1; i<=height; i++){
for (int j=1; j<=1; j++)
system.out.print("*");
system.out.println();
Scanner scan = new Scanner(System.in);
int sides;
System.out.print("How many sides?");
sides = scan.nextInt();
Diamond d = new Diamond(6); // Constructor, for a Diamond object of side-length n
d.printOut(); // Prints the Diamond shape to the screen
}
}
}

Best answer:

I’m not sure if this will fix all your problems, but the first two lines in your for loops: system.out.print(“*”);
system.out.printlin();
need to be capitalized: System.out.print(“*”);
System.out.println();

By Barcode Scanner Add comment

java-can not find symbol error?

July 16th, 2006 at 10:36pm Under Forum

java-can not find symbol error?
I have the following error of can not find symbol error, what I have attempted to do is assign a string for name known as ‘i’, where does this need to be declared in order to compile successfully?

Here is my code:
import java.util.Scanner;

class jets24
{
public static void main (String[]args)
{
Scanner input= new Scanner (System.in);

//variables//

int TotalLuxurySeats = 4 ;
int TotalExecutiveSeats = 6 ;
int Option = 0 ;
int LuxurySeatsSold=0;
int ExectutiveSeatsSold=0;
String[] CustomerName= new String [10];

while(Option!=4 || LuxurySeatsSold>0 || ExectutiveSeatsSold>0)
{
System.out.println(” Hello and welcome to CCNJet! “);

System.out.println(” “);

System.out.println(” Please select an option from the following menu “);
System.out.println(” “);
System.out.println(” 1. Book a luxury seat “);
System.out.println(” 2. Book an exectutive seat “);
System.out.println(” 3. Display seat details/availability “);
System.out.println(” 4. Exit “);
Option=input.nextInt();

if ((Option==1) && (LuxurySeatsSold<4))
{
System.out.println(" Please enter your name ");
CustomerName[LuxurySeatsSold]=input.next();
System.out.println(" ");
System.out.println(" Thank you for your luxury seat order " + CustomerName[LuxurySeatsSold] + " You have seat number " + (LuxurySeatsSold + 1));
LuxurySeatsSold++;
LuxurySeatsSold=TotalLuxurySeats -1;
}
if ((Option==2) && ExectutiveSeatsSold<4)
{
System.out.println(" Please enter your name ");
CustomerName[ExectutiveSeatsSold]=input.next();
System.out.println(" ");
System.out.println(" Thank you for your exectutive seat order " + CustomerName[ExectutiveSeatsSold] + " You have seat number " + (ExectutiveSeatsSold+ 1));
ExectutiveSeatsSold++;
ExectutiveSeatsSold=TotalExecutiveSeats -1;
}
if (Option==3)
{
System.out.println(" Here is a report of available/unavailable seats on the aircraft ");
System.out.println("");

System.out.println(" Luxury seats ");
while (CustomerName[i]!=null)//for (int i=0;j<4;i++) //cannot find symbol-variable i//
{
if(customerName[i]==null) break;
System.out.println("Seat Number: " + i + "Name: " + customerName[i]);

}
System.out.println("Executive Seats");
while(CustomerName[k]!=null)//for( k=4;l<10;k++)
{
if(customerName[k]==null) break;

System.out.println("Seat Number : " + k + "Name: " + customerName[i]); }

}
}
if (Option==4)
{
System.out.println("=============");
System.out.println(" Good bye,thanks for looking!");
System.out.println("=========");

}
}
}

Many thanks,

Ben

Best answer:

You declare a variable in a scope in which it will be used.

By Barcode Scanner Add comment

Next Posts Previous Posts


Categories