Hi guys

I am trying to build a program which scans data from a text file, but I keep getting an error when trying to compile it.

The code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;

class anything extends JFrame
{
	public anything()
	{
		File stuff = new File(stuff.txt);
		Scanner scan = Scanner(stuff);
		int length; 
		int count = 0;
		double place;
			
			while(scan.hasNextDouble())
			{
				place = scan.NextDouble();
					count++;
			}

This isn't the whole program, but is the part which has Scanner.

The errors

cannot find symbol variable txt
cannot find symbol method Scanner(java.io.File)
cannot find symbol method NextDouble()

So what is the problem, I have a feeling it has to do with the importing of scanner or something.

This: File stuff = new File(stuff.txt); Should be: File stuff = new File([B]"[/B]stuff.txt[B]"[/B]); This: Scanner scan = Scanner(stuff); Should be: Scanner scan = [B]new[/B] Scanner(stuff); This: place = scan.NextDouble(); I think should be: place = scan.[B]n[/B]extDouble(); Look at this: Scanner

Thanks very much man, I never would have found such an annoying error.

Thanks!

import java.util.Scanner;
class Handling
{
    public static int quotient(int a,int b)
    {

        return(a/b);

    }
public static void main(String[] arg)
{
    Scanner scanner=new Scanner(System.in);

    System.out.println(" enter value of a");

    int a=scanner.nextInt();

    System.out.println(" enter value of b");

    int b=scanner.nextInt();

    int result=quotient(a,b);

    System.out.println("\n result: a / b =  " +result);

    try 
    {
        result=quotient(a,b);
    }
    catch(Exception e)
    {
        System.out.println(" this is catch");
    }
    finally
    {
        System.out.println(" this is finally");
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.