LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2008, 08:38 AM   #1
malayletsrock
LQ Newbie
 
Registered: Dec 2007
Distribution: fedora core
Posts: 13

Rep: Reputation: 0
why is Scanner class of java not working on fedora 7


i have installed JDK 1.6 on my fedora 7 , all my java programs are running fine except for those that use Scanner class uner UTIL package.
it says "cannot resolve to a type" , i checked and found that Scanner class is there where jdk is placed under /usr/java/jdk1.6/src/java/util

is there some problem in class or what because everything else is running fine.
note*:i am using fedora under vmvare.
 
Old 07-09-2008, 09:23 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
What program/process is it that's giving you the "cannot resolve to a type" error - is it through Netbeans or Eclipse, or is it through trying to compile from the command line?

I have Java 6 (1.6) installed from the sun-java6-jdk package in Debian, and I don't have any problems with the java.util.Scanner class - I use it for practically anything I/O related (as a reader). The only time I have ever had an issue with it was when I compiled it with "javac" and tried to run it with "java" while I had GCJ installed - under Debian, the "java" command associated with GCJ takes precedence over Sun's "java" command. The GCJ implementation does not have the java.util.Scanner class (which is bogus).

Make sure, when you're running it, if you're trying to do so from the command line, that you're not accidentally invoking the GCJ "java"; to check this, if you have both GCJ and Sun Java installed is to run "java -version".

If you're getting this from an IDE, tell us which IDE, and I can try and help you figure out what the issue may be.
 
Old 07-11-2008, 09:03 AM   #3
malayletsrock
LQ Newbie
 
Registered: Dec 2007
Distribution: fedora core
Posts: 13

Original Poster
Rep: Reputation: 0
ya i am running it through command line,i am not using any IDE,tell me what should i do to invoke sun jdk1.6 and overrule GCJ
 
Old 07-11-2008, 09:49 AM   #4
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Some weird things I've noticed, is that something may compile perfectly fine under GCJ, but not run afterwards, and it would give me errors like the one you've listed above (either after a native, or bytecode, compilation).

Since the command to compile stuff with GCJ is - oddly enough - "gcj", we don't need to worry about the "javac" command being doubled - however, the GCJ package does supply a "java" command, which is troublesome.

To isolate the Sun Java RE:
1. In a console, run
Code:
$ which javac
and it should give you something like "/usr/lib/jdk1.6/bin/javac". It will probably be different, but you never know. Just take note of the path before the "javac".

2. Open up your text editor of choice, and open your .bashrc file (located in your home directory - "~"). Anywhere in the file, add the following:
Code:
alias java='/usr/lib/jdk1.6/bin/java'
3. Back in a terminal, source your update .bashrc:
Code:
$ source ~/.bashrc
Sun supplies all of its Java-centric tools in one directory, which is really nice, so the location of the Java "javac" compiler, will also have the "java" runtime environment in it. Alternately, instead of "java" being the name of the alias, you could use "sun-java" or whatever you prefer.
 
Old 07-11-2008, 11:34 AM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Actually, I would strongly suggest just de-installing GJC. This insures that every application on your system is always using the Sun JDK.

Life will be much easier and much happier, for many different reasons.

IMHO .. PSM
 
Old 07-11-2008, 12:17 PM   #6
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
That's quite a decent suggestion, PSM.

Although GCJ is a piece of crap, I think it's neat that I can write basic Java programs and compile them to native code. I prefer Java to C and C++ when it comes to GUI programming, hence I find the GCJ project interesting, but it is still WAY too young for any sort of production use.
 
Old 07-12-2008, 04:55 PM   #7
malayletsrock
LQ Newbie
 
Registered: Dec 2007
Distribution: fedora core
Posts: 13

Original Poster
Rep: Reputation: 0
i have updated the bashrc file with that alias command , and also executed that source command , but still that same error is coming , i think the jdk java is not invoked still
 
Old 07-13-2008, 12:58 PM   #8
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Where are the binaries (java, javac, jar, javaw, javah, etc.) of your Sun Java JDK located?

Are they in /usr/lib, or /opt, or...?
 
Old 07-13-2008, 11:13 PM   #9
malayletsrock
LQ Newbie
 
Registered: Dec 2007
Distribution: fedora core
Posts: 13

Original Poster
Rep: Reputation: 0
The binary files(java,javac etc ) are located in /usr/java/jdk1.6.0_03/bin
 
Old 07-14-2008, 07:35 AM   #10
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
When you edited your ~/.bashrc file, did you "source" it afterwards, by any chance?

Code:
--- ~/.bashrc ---
export JDKPATH=/usr/java/jdk1.6.0_03/bin

alias java=$JDKPATH/java
alias javac=$JDKPATH/javac
-----------------

$ source ~/.bashrc
Then try it.
 
Old 07-15-2008, 01:33 AM   #11
malayletsrock
LQ Newbie
 
Registered: Dec 2007
Distribution: fedora core
Posts: 13

Original Poster
Rep: Reputation: 0
ya have done all this but still that gcj javac command is comming in play
 
Old 07-15-2008, 07:45 AM   #12
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
The GCJ package doesn't ship with a "javac" command, though - the GCJ-equivalent is the "gcj" command. It does, however, ship with a "java" command. Is it running it, or compiling it that is providing the error?
 
Old 07-15-2008, 02:24 PM   #13
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi again, malayletsrock -

I wasn't joking. I'd seriously consider de-installing GJC until you're thoroughly comfortable using the Sun JDK. It will be *much* easier to get things working. You can always re-install GJC again later, if you want it.

IMHO .. PSM
 
Old 07-16-2008, 07:38 AM   #14
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I'm definitely in full agreement with paulsm4, here. Just flat-out uninstall GCJ and see if the problem corrects itself. If all else fails, uninstall both GCJ and the Sun JDK, download the latest binary installer from http://java.sun.com/ and install from that - that will be guaranteed to work.

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java - one class for all? Java Design. trscookie Programming 4 02-07-2008 06:06 PM
Running a Java executable class from another executable class LUB997 Programming 22 07-24-2005 04:57 AM
visioneer 5800 scanner not working in fedora Ravager Fedora 4 11-13-2004 12:00 PM
Compile Java - .class, .java, .jar ? woranl Programming 2 11-09-2004 10:12 PM
Fedora 2 Mozilla flash/java not working delphipgmr Linux - Newbie 8 11-09-2004 02:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration