Jump to content

Learning and in troubles

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Mesh89

Mesh89

    Newbie

  • Members
  • Pip
  • 5 posts
Hi, I'm learning Java from the official Tutorial, but I'm having troubles with Scanner. I downloaded this:

import java.io.FileReader;

import java.io.BufferedReader;

import java.io.IOException;

import java.util.Scanner;

import java.util.Locale;


public class ScanSum {

    public static void main(String[] args) throws IOException {

        Scanner s = null;

        double sum = 0;

        try {

            s = new Scanner(

                    new BufferedReader(new FileReader("usnumbers.txt")));

            s.useLocale(Locale.US);



            while (s.hasNext()) {

                if (s.hasNextDouble()) {

                        sum += s.nextDouble();

                    } else {

                        s.next();

                    }   

            }

        } finally {

            s.close();

        }


        System.out.println(sum);

    }

}

and when I try to compile using javac (same result using gcj) I get this

----------
1. ERROR in ScanSum.java (at line 35)
import java.util.Scanner;
^^^^^^^^^^^^^^^^^
The import java.util.Scanner cannot be resolved
----------
2. ERROR in ScanSum.java (at line 40)
Scanner s = null;
^^^^^^^
Scanner cannot be resolved to a type
----------
3. ERROR in ScanSum.java (at line 43)
s = new Scanner(
^^^^^^^
Scanner cannot be resolved to a type
----------
3 problems (3 errors)

Anyone knows what's going on? :(

#2
Arkie

Arkie

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
Either you don't have java 1.5+ installed or classpath/filepath problem

#3
Mesh89

Mesh89

    Newbie

  • Members
  • Pip
  • 5 posts
I'm using Ubuntu, how can I see if it's installed correctly?

#4
Mesh89

Mesh89

    Newbie

  • Members
  • Pip
  • 5 posts
javac -v gives this:

Eclipse Java Compiler v_774_R33x, 3.3.1, Copyright IBM Corp 2000, 2007. All rights reserved.

Shouldn't it be from Sun?

#5
Mesh89

Mesh89

    Newbie

  • Members
  • Pip
  • 5 posts
I was probably missing the JDK, because I installed openJDK and now works great ;)

#6
niaz333

niaz333

    Newbie

  • Members
  • Pip
  • 2 posts
hi

i read your massege. I think you install latest varsion of java and c/c++

thanks again

#7
tossy

tossy

    Programmer

  • Members
  • PipPipPipPipPip
  • 202 posts
Well, r u using new version of Java ?

#8
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
I would recommend you not to use openJDK, glassfish isn't fully supported then :/
Posted Image