my java is broken !

Discussion in 'Java' started by bilsch, Apr 29, 2012.

  1. bilsch

    bilsch Guest

    I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    character array. It worked fine. The program is listed below. It has
    only 24 lines. Today when I run it, it has weird errors referenced to
    line numbers 2442, 2685 and 1620. When I click on those error messages
    it shows lines in a completely different program - a program that I
    never wrote for sure. I saved the file with a different name and it runs
    fine with that name - no errors. The file name that has the problem is
    Nvj5. That is the file selected and displayed when I click RUN FILE. It
    is the file listed below. Even though it is selected and displayed when
    I click RUN FILE my system is running some other huge file instead. Has
    anyone ever heard of a problem like this?

    import java.io.*;

    public class Nvj5 {

    public static void main(String[] args){

    try {
    FileInputStream file = new FileInputStream("NVRAM.TXT");
    char[] nvchr = new char [30000];
    int fin = 1;
    int count = 1;
    while (fin != -1) {
    fin = file.read();
    nvchr[count] = (char) fin;
    System.out.print(nvchr[count]);
    count++;
    }
    System.out.println("Bytes read : " + count);
    file.close();
    } catch (IOException e){
    System.out.println("Could not read file");
    }

    }
    }
     
    bilsch, Apr 29, 2012
    #1
    1. Advertising

  2. bilsch

    Stefan Ram Guest

    bilsch <> writes:
    >I click RUN FILE my system is running some other huge file instead.


    Possibly, an exception was thrown from the standard library and
    the line number shows where in the standard library it did originate.
     
    Stefan Ram, Apr 29, 2012
    #2
    1. Advertising

  3. bilsch

    bilsch Guest

    On 04/29/2012 05:26 AM, Stefan Ram wrote:
    > bilsch<> writes:
    >> I click RUN FILE my system is running some other huge file instead.

    >
    > Possibly, an exception was thrown from the standard library and
    > the line number shows where in the standard library it did originate.
    >

    Do you think it could be due to a virus? I'm running Linux Ubuntu - the
    linux heads all say there's no anti-virus programs for linux.
     
    bilsch, Apr 29, 2012
    #3
  4. bilsch

    Roedy Green Guest

    On Sun, 29 Apr 2012 05:36:32 -0700, bilsch <>
    wrote, quoted or indirectly quoted someone who said :

    >Do you think it could be due to a virus? I'm running Linux Ubuntu - the
    >linux heads all say there's no anti-virus programs for linux.


    Viruses are blamed all the time for errors the user made and bugs in
    the OS. When you are programming it is nearly always your own fault.

    If you get a stack trace, look for the line in your own program not
    ones in the standard library.

    If you get a mysterious compiler error see
    http://mindprod.com/jgloss/compilererrormessages.html

    If you are seeking help, you need to list the program and the compiler
    error message and indicate where in the program each error message is
    pointing.

    Try compiling without an IDE using just JavaC in case the problem is
    misunderstanding how to use the IDE.
    see http://mindprod.com/jgloss/javacexe.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Programmers love to create simplified replacements for HTML.
    They forget that the simplest language is the one you
    already know. They also forget that their simple little
    markup language will bit by bit become even more convoluted
    and complicated than HTML because of the unplanned way it grows.
    ..
     
    Roedy Green, Apr 29, 2012
    #4
  5. On 4/29/2012 7:13 AM, bilsch wrote:
    > I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    > character array. It worked fine. The program is listed below. It has
    > only 24 lines. Today when I run it, it has weird errors referenced to
    > line numbers 2442, 2685 and 1620. When I click on those error messages
    > it shows lines in a completely different program - a program that I
    > never wrote for sure. I saved the file with a different name and it runs
    > fine with that name - no errors. The file name that has the problem is
    > Nvj5. That is the file selected and displayed when I click RUN FILE. It
    > is the file listed below. Even though it is selected and displayed when
    > I click RUN FILE my system is running some other huge file instead. Has
    > anyone ever heard of a problem like this?


    When you refuse to mention error messages, the answer becomes "I have no
    clue."

    It would also help to know what the command line is that is causing it.
    It could be that your IDE is buggy, too (since it sounds like you rely
    on a specific IDE feature).

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Apr 29, 2012
    #5
  6. bilsch

    bilsch Guest

    On 04/29/2012 07:25 AM, Joshua Cranmer wrote:
    > On 4/29/2012 7:13 AM, bilsch wrote:
    >> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    >> character array. It worked fine. The program is listed below. It has
    >> only 24 lines. Today when I run it, it has weird errors referenced to
    >> line numbers 2442, 2685 and 1620. When I click on those error messages
    >> it shows lines in a completely different program - a program that I
    >> never wrote for sure. I saved the file with a different name and it runs
    >> fine with that name - no errors. The file name that has the problem is
    >> Nvj5. That is the file selected and displayed when I click RUN FILE. It
    >> is the file listed below. Even though it is selected and displayed when
    >> I click RUN FILE my system is running some other huge file instead. Has
    >> anyone ever heard of a problem like this?

    >
    > When you refuse to mention error messages, the answer becomes "I have no
    > clue."
    >
    > It would also help to know what the command line is that is causing it.
    > It could be that your IDE is buggy, too (since it sounds like you rely
    > on a specific IDE feature).
    >

    I can't tell you the error messages now because I deleted the offending
    file - so can't generate errors anymore. It seems the error messages
    are irrelevant since they point to lines in some large unknown program.
     
    bilsch, Apr 29, 2012
    #6
  7. On 12-04-29 07:21 PM, bilsch wrote:
    > On 04/29/2012 07:25 AM, Joshua Cranmer wrote:
    >> On 4/29/2012 7:13 AM, bilsch wrote:
    >>> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    >>> character array. It worked fine. The program is listed below. It has
    >>> only 24 lines. Today when I run it, it has weird errors referenced to
    >>> line numbers 2442, 2685 and 1620. When I click on those error messages
    >>> it shows lines in a completely different program - a program that I
    >>> never wrote for sure. I saved the file with a different name and it runs
    >>> fine with that name - no errors. The file name that has the problem is
    >>> Nvj5. That is the file selected and displayed when I click RUN FILE. It
    >>> is the file listed below. Even though it is selected and displayed when
    >>> I click RUN FILE my system is running some other huge file instead. Has
    >>> anyone ever heard of a problem like this?

    >>
    >> When you refuse to mention error messages, the answer becomes "I have no
    >> clue."
    >>
    >> It would also help to know what the command line is that is causing it.
    >> It could be that your IDE is buggy, too (since it sounds like you rely
    >> on a specific IDE feature).
    >>

    > I can't tell you the error messages now because I deleted the offending
    > file - so can't generate errors anymore. It seems the error messages
    > are irrelevant since they point to lines in some large unknown program.


    Your system is not "running" some other "file", not in the sense that
    you think. Your Java source files are compiled into .class files, these
    are loaded up into memory as required, and broadly speaking it's the
    bytecodes in these class files that get executed ("run"). The first
    application code to execute is the proper main() method in your main
    class...like Nvj5.main(). Since you are using standard library code
    also, like FileInputStream, code in those classes - and in the classes
    that FileInputStream uses, and so on and so on - also gets executed.

    That mysterious huge file is a standard library class that your code
    needs to work. It's not irrelevant. A high percentage of the time when
    you write buggy code the errors start in library code, not in your own
    code. You need to look at the entire stack. You will notice that
    somewhere in the stack are line references to your own code also.

    You deleted and renamed *which* files exactly? Also, you have a class
    Nvj5 but a corresponding source file "Nvj5.java". You'll find that
    people understand you better if you differentiate between data files
    (like NVRAM.TXT) and source files (like Nvj5.java).

    Are you saying that you renamed class Nvj5 in source file Nvj5.java to
    class Pwll12 in source file Pwll12.java, say, and ever since your
    program has run like a charm? That seems highly unlikely. In fact that's
    astronomically unlikely.

    What IDE or programming text editor are you using? How many "main"
    classes are currently available in your workspace? When you tried that
    failing run did you see any console output at all?

    AHS
    --
    A fly was very close to being called a "land," cause that's what they do
    half the time.
    -- Mitch Hedberg
     
    Arved Sandstrom, Apr 30, 2012
    #7
  8. bilsch

    bilsch Guest

    On 04/29/2012 04:06 PM, Arved Sandstrom wrote:
    > On 12-04-29 07:21 PM, bilsch wrote:
    >> On 04/29/2012 07:25 AM, Joshua Cranmer wrote:
    >>> On 4/29/2012 7:13 AM, bilsch wrote:
    >>>> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    >>>> character array. It worked fine. The program is listed below. It has
    >>>> only 24 lines. Today when I run it, it has weird errors referenced to
    >>>> line numbers 2442, 2685 and 1620. When I click on those error messages
    >>>> it shows lines in a completely different program - a program that I
    >>>> never wrote for sure. I saved the file with a different name and it runs
    >>>> fine with that name - no errors. The file name that has the problem is
    >>>> Nvj5. That is the file selected and displayed when I click RUN FILE. It
    >>>> is the file listed below. Even though it is selected and displayed when
    >>>> I click RUN FILE my system is running some other huge file instead. Has
    >>>> anyone ever heard of a problem like this?
    >>>
    >>> When you refuse to mention error messages, the answer becomes "I have no
    >>> clue."
    >>>
    >>> It would also help to know what the command line is that is causing it.
    >>> It could be that your IDE is buggy, too (since it sounds like you rely
    >>> on a specific IDE feature).
    >>>

    >> I can't tell you the error messages now because I deleted the offending
    >> file - so can't generate errors anymore. It seems the error messages
    >> are irrelevant since they point to lines in some large unknown program.

    >
    > Your system is not "running" some other "file", not in the sense that
    > you think. Your Java source files are compiled into .class files, these
    > are loaded up into memory as required, and broadly speaking it's the
    > bytecodes in these class files that get executed ("run"). The first
    > application code to execute is the proper main() method in your main
    > class...like Nvj5.main(). Since you are using standard library code
    > also, like FileInputStream, code in those classes - and in the classes
    > that FileInputStream uses, and so on and so on - also gets executed.
    >
    > That mysterious huge file is a standard library class that your code
    > needs to work. It's not irrelevant. A high percentage of the time when
    > you write buggy code the errors start in library code, not in your own
    > code. You need to look at the entire stack. You will notice that
    > somewhere in the stack are line references to your own code also.
    >
    > You deleted and renamed *which* files exactly? Also, you have a class
    > Nvj5 but a corresponding source file "Nvj5.java". You'll find that
    > people understand you better if you differentiate between data files
    > (like NVRAM.TXT) and source files (like Nvj5.java).
    >
    > Are you saying that you renamed class Nvj5 in source file Nvj5.java to
    > class Pwll12 in source file Pwll12.java, say, and ever since your
    > program has run like a charm? That seems highly unlikely. In fact that's
    > astronomically unlikely.
    >

    I copied the source from the offending file then I deleted the entire
    project folder - everything. Then I created a new project and a new
    blank .java file and pasted the copied source in that new file. I used
    new names for the new file and folder. Once I did that the source(in
    the new file) ran without a glitch. I tested it several times over a
    period of days and it always worked. NOW, TODAY THE NEW FILE HAS GOTTEN
    THE SAME PROBLEM JUST LIKE THE OLD FILE I have the error information
    pasted below along with the source, also below. The error lines are in a
    different file than the one I am running - now named Nvr1.java..

    > What IDE or programming text editor are you using? How many "main"
    > classes are currently available in your workspace? When you tried that
    > failing run did you see any console output at all?
    >

    I am using NetBeans to do exerything.

    > AHS


    THE ERROR INFORMATION:
    run:
    Exception in thread "main" java.lang.VerifyError: Constructor must call
    super() or this() before return in method Nvr1.<init>()V at offset 0
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 4 seconds)


    THE SOURCE:
    import java.io.*;

    public class Nvr1 {

    public static void main(String[] args){

    try {
    FileInputStream file = new FileInputStream("NVRAM.TXT");
    char[] nvchr = new char [30000];
    int fin = 1;
    int count = 1;
    while (fin != -1) {
    fin = file.read();
    nvchr[count] = (char) fin;
    System.out.print(nvchr[count]);
    count++;
    }
    System.out.println("Bytes read : " + count);
    file.close();
    } catch (IOException e){
    System.out.println("Could not read file");
    }

    }
    }

    TIA. Bill S.
     
    bilsch, May 3, 2012
    #8
  9. bilsch

    Lew Guest

    bilsch wrote:
    > Arved Sandstrom wrote:
    >>>> bilsch wrote:
    >>>>> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
    >>>>> character array. It worked fine. The program is listed below. It has
    >>>>> only 24 lines. Today when I run it, it has weird errors referenced to
    >>>>> line numbers 2442, 2685 and 1620. When I click on those error messages
    >>>>> it shows lines in a completely different program - a program that I
    >>>>> never wrote for sure. I saved the file with a different name and it runs
    >>>>> fine with that name - no errors. The file name that has the problem is
    >>>>> Nvj5. That is the file selected and displayed when I click RUN FILE. It
    >>>>> is the file listed below. Even though it is selected and displayed when
    >>>>> I click RUN FILE my system is running some other huge file instead. Has
    >>>>> anyone ever heard of a problem like this?

    .. . .
    >> Your system is not "running" some other "file", not in the sense that
    >> you think. Your Java source files are compiled into .class files, these
    >> are loaded up into memory as required, and broadly speaking it's the
    >> bytecodes in these class files that get executed ("run"). The first
    >> application code to execute is the proper main() method in your main
    >> class...like Nvj5.main(). Since you are using standard library code
    >> also, like FileInputStream, code in those classes - and in the classes
    >> that FileInputStream uses, and so on and so on - also gets executed.
    >>

    .. . .
    > I copied the source from the offending file then I deleted the entire
    > project folder - everything. Then I created a new project and a new
    > blank .java file and pasted the copied source in that new file. I used
    > new names for the new file and folder. Once I did that the source(in
    > the new file) ran without a glitch. I tested it several times over a
    > period of days and it always worked. NOW, TODAY THE NEW FILE HAS GOTTEN
    > THE SAME PROBLEM JUST LIKE THE OLD FILE I have the error information


    What do you mean by "FILE", exactly?

    Files don't execute in Java.

    > pasted below along with the source, also below. The error lines are in a
    > different file than the one I am running - now named Nvr1.java..


    The error message clearly states, "method Nvr1.<init>()V". That is definitely in your class. It is, in fact, the initializer of your class.

    How do you conclude otherwise?

    > THE ERROR INFORMATION:
    > run:
    > Exception in thread "main" java.lang.VerifyError: Constructor must call
    > super() or this() before return in method Nvr1.<init>()V at offset 0
    > at java.lang.Class.getDeclaredMethods0(Native Method)
    > at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    > at java.lang.Class.getMethod0(Class.java:2685)
    > at java.lang.Class.getMethod(Class.java:1620)
    > at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
    > at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
    > Java Result: 1
    > BUILD SUCCESSFUL (total time: 4 seconds)
    >
    >
    > THE SOURCE:
    > import java.io.*;
    >
    > public class Nvr1 {
    >
    > public static void main(String[] args){
    >
    > try {
    > FileInputStream file = new FileInputStream("NVRAM.TXT");
    > char[] nvchr = new char [30000];
    > int fin = 1;
    > int count = 1;
    > while (fin != -1) {
    > fin = file.read();
    > nvchr[count] = (char) fin;


    Why aren't you using the first element of the array?

    > System.out.print(nvchr[count]);
    > count++;
    > }


    What happens if 'count' equals '30000'?

    > System.out.println("Bytes read : " + count);
    > file.close();
    > } catch (IOException e){
    > System.out.println("Could not read file");
    > }
    >
    > }
    > }


    The problem, based on what we've seen here, might be in the way the command is invoked. It depends on being run from the correct directory with all the right libraries in its classpath. If those conditions don't hold, you could get weird results.

    That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.

    What happens (i.e., copy and paste the output) when you run the program from the command line?

    --
    Lew
     
    Lew, May 4, 2012
    #9
  10. On 12-05-03 08:05 PM, Lew wrote:
    [ SNIP ]

    > That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.

    [ SNIP ]

    It doesn't jibe, no. OTOH, a search on the VerifyError message +
    "NetBeans" does turn up indications that NB exhibits this error in
    several situations. Often solved, just as with Eclipse in umpteen
    circumstances, with the classic "Clean-Rebuild-Try Again-Curse-Repeat"
    cycle.

    I wouldn't rule out that there is NetBeans badness here. I figure most
    of us have encountered situations where you open up an IDE on a project,
    where the day before everything was OK, and now suddenly it's seriously
    out of whack.

    Your suggestion to have the OP try the build and run on the command line
    is a great idea. I strongly second that.

    AHS
    --
    A fly was very close to being called a "land," cause that's what they do
    half the time.
    -- Mitch Hedberg
     
    Arved Sandstrom, May 4, 2012
    #10
  11. bilsch

    bilsch Guest

    On 05/03/2012 04:44 PM, Arved Sandstrom wrote:
    > On 12-05-03 08:05 PM, Lew wrote:
    > [ SNIP ]
    >
    >> That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.

    > [ SNIP ]
    >
    > It doesn't jibe, no. OTOH, a search on the VerifyError message +
    > "NetBeans" does turn up indications that NB exhibits this error in
    > several situations. Often solved, just as with Eclipse in umpteen
    > circumstances, with the classic "Clean-Rebuild-Try Again-Curse-Repeat"
    > cycle.
    >
    > I wouldn't rule out that there is NetBeans badness here. I figure most
    > of us have encountered situations where you open up an IDE on a project,
    > where the day before everything was OK, and now suddenly it's seriously
    > out of whack.
    >
    > Your suggestion to have the OP try the build and run on the command line
    > is a great idea. I strongly second that.
    >
    > AHS


    Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    Offending program, Nvr1.java is in directory:

    /home/bilsch/NetBeansProjects/NVRAM/src/

    environment variable PATH is:

    /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    However note that when I run; java Nvr1.class (or simply Nvr1) from my
    home directory the output errors are in javanese, as follows:

    bilsch@p4pwj:~/jdk7/bin$ java Nvr1
    Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1
    Caused by: java.lang.ClassNotFoundException: Nvr1
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    Could not find the main class: Nvr1. Program will exit.
    bilsch@p4pwj:~/jdk7/bin$ cd
    bilsch@p4pwj:~$ java Nvr1.class
    Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1/class
    Caused by: java.lang.ClassNotFoundException: Nvr1.class
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

    Could not find the main class: Nvr1.class. Program will exit.

    Therefore the command line is hooked up with the java directory -
    regardless of the PATH.

    When I change working directory to /home/bilsch/jdk7/bin/ and type in
    the path and filename for the offending file I get the following output:

    bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1

    The program 'javac' can be found in the following packages:
    * openjdk-6-jdk
    * ecj
    * gcj-4.4-jdk
    * gcj-4.6-jdk
    * gcj-4.5-jdk
    * openjdk-7-jdk
    Try: sudo apt-get install <selected package>
    bilsch@p4pwj:~/jdk7/bin$
    bilsch@p4pwj:~/jdk7/bin$

    Ubuntu can't find javac even though I ran it from the directory where
    javac resides. It can't find it from the home directory either.

    THE SHORT ANSWER IS I CAN'T COMPILE OR RUN JAVA FROM MY LINUX COMMAND
    LINE. I can't answer your question of what the output is when running
    command line. Also I have no idea why Linux won't do it. I'LL HAVE TO
    WORK ON THAT.

    I have to figure how to run from command line in linux. If I could run
    using Windows command line and it worked that would be inconclusive ie.
    taking Linux out of the equation. If I could run it in Windows command
    line tonight and it worked OK that wouldn't mean it would still work 4
    days from now?

    This could be a Linux glitch rather than Java.

    Thanks for listening. Bill S.
     
    bilsch, May 4, 2012
    #11
  12. bilsch

    Lew Guest

    bilsch wrote:
    > Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    > Offending program, Nvr1.java is in directory:
    >
    > /home/bilsch/NetBeansProjects/NVRAM/src/
    >
    > environment variable PATH is:
    >
    > /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    >
    > However note that when I run; java Nvr1.class (or simply Nvr1) from my
    > home directory the output errors are in javanese, as follows:
    >
    > bilsch@p4pwj:~/jdk7/bin$ java Nvr1
    > Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1
    > Caused by: java.lang.ClassNotFoundException: Nvr1
    > at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    > at java.security.AccessController.doPrivileged(Native Method)
    > at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    > Could not find the main class: Nvr1. Program will exit.
    > bilsch@p4pwj:~/jdk7/bin$ cd
    > bilsch@p4pwj:~$ java Nvr1.class
    > Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1/class
    > Caused by: java.lang.ClassNotFoundException: Nvr1.class
    > at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    > at java.security.AccessController.doPrivileged(Native Method)
    > at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    >
    > Could not find the main class: Nvr1.class. Program will exit.
    >
    > Therefore the command line is hooked up with the java directory -
    > regardless of the PATH.


    Huh?

    Besides that I'm not sure what you mean by "the command line is hooked up with the java directory", there is no reason to associate the PATH envar with the error you show, which is simply due to the fact that you did not specify the classpath correctly. Or at all. And tried to run the Java program from a directory such that the default classpath does not include it.


    > When I change working directory to /home/bilsch/jdk7/bin/ and type in
    > the path and filename for the offending file I get the following output:
    >
    > bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1
    >
    > The program 'javac' can be found in the following packages:
    > * openjdk-6-jdk
    > * ecj
    > * gcj-4.4-jdk
    > * gcj-4.6-jdk
    > * gcj-4.5-jdk
    > * openjdk-7-jdk
    > Try: sudo apt-get install <selected package>
    > bilsch@p4pwj:~/jdk7/bin$
    > bilsch@p4pwj:~/jdk7/bin$
    >
    > Ubuntu can't find javac even though I ran it from the directory where
    > javac resides. It can't find it from the home directory either.
    >
    > THE SHORT ANSWER IS I CAN'T COMPILE OR RUN JAVA FROM MY LINUX COMMAND
    > LINE. I can't answer your question of what the output is when running


    Shh.

    > command line. Also I have no idea why Linux won't do it. I'LL HAVE TO
    > WORK ON THAT.


    Shh.

    You showed us the output. Why do you say you can't answer the question thatyou just answered?

    > I have to figure how to run from command line in linux. If I could run


    You could try reading the documentation for the "java" command.

    Try this:

    $ java -cp ${directory_where_the_class_file_is} Nvr1

    > using Windows command line and it worked that would be inconclusive ie.
    > taking Linux out of the equation. If I could run it in Windows command
    > line tonight and it worked OK that wouldn't mean it would still work 4
    > days from now?


    If you were to specify the command line correctly, it would work right now,in Linux.

    > This could be a Linux glitch rather than Java.


    No, it's operator error.

    Neither Linux nor Java is at fault.

    You need to read the documentation for the commands you're using, is all.

    Had you done so, you'd've known up front that "java Nvr1.class" is wrong always, and why your attempt to run "java Nvr1" without a matching classpath failed.

    Which it would do in the same way in Windows for the same reason.

    RTFM.

    --
    Lew
     
    Lew, May 4, 2012
    #12
  13. bilsch <> wrote:
    > environment variable PATH is:
    > /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games


    > bilsch@p4pwj:~/jdk7/bin$ java Nvr1


    You don't have "." or ~/jdk7/bin in your PATH. So it probably has
    picked up some system-installed java from /usr/bin

    Add the bin directory of your jdk7 to the beginning of your PATH,
    and some of your obstacles might dissolve.

    Anyway, your Nvr1.class file surely isn't in ~/jdk7/bin, so the
    > Could not find the main class: Nvr1. Program will exit.

    was to be expected.

    > bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1
    > The program 'javac' can be found in the following packages:


    That's a shell-convenience, and it seems like you have a jre
    installed system-wide, but not a jdk.

    To actually use your priovate jdk7 installation, you have to
    add it to your PATH (and before /usr/bin)

    Your PATH probably should look like:
    /home/bilsch/jdk7/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    (I'm speculating about your actual home-directory here)
     
    Andreas Leitgeb, May 4, 2012
    #13
  14. bilsch

    bilsch Guest

    On 05/04/2012 07:11 AM, Leif Roar Moldskred wrote:
    > bilsch<> wrote:
    >
    >>
    >> Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    >> Offending program, Nvr1.java is in directory:
    >>
    >> /home/bilsch/NetBeansProjects/NVRAM/src/
    >>
    >> environment variable PATH is:
    >>
    >> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    >
    > And there's your problem -- your PATH does not contain the directory
    > your java and javac commands are found in, neither as an explicit
    > entry of /home/bilsch/jdk7/bin/ or implicitly through the current
    > directory .
    >
    >> However note that when I run; java Nvr1.class (or simply Nvr1) from my
    >> home directory the output errors are in javanese, as follows:
    >>
    >> bilsch@p4pwj:~/jdk7/bin$ java Nvr1
    >> Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1
    >> Caused by: java.lang.ClassNotFoundException: Nvr1

    >
    > You're running a java command here, but not the one at
    > /home/bilsch/jdk7/bin/java -- you must have another java command in
    > your system somewhere. (Try the command "which java" to show where
    > the java command that's actually being run is.)
    >
    > The solution is to add the directory /home/bilsch/jdk7/bin/ to the
    > front of your PATH. Write the following command on the command line:
    >
    > export PATH=/home/bilsch/jdk7/bin/:$PATH
    >
    > You should then be able to call javac, use that to create a .class
    > file and then use java to run the class file.
    >


    I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
    run program Nvr1 from the command line. Also, when I then go into
    NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
    IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
    /home/bilsch/jdk7/bin part has been removed. I even put the PATH change
    in two different places in the PATH variable and both were removed. Does
    anybody have a java IDE other than NetBeans ?

    Also, a pain in the ass is I must change directory to where the source
    file resides to compile. I must change directory to where the .class
    file resides in order to run. These directories are different for every
    project therefore it's not practical to automate with a script.

    Bill S.
     
    bilsch, May 4, 2012
    #14
  15. On Fri, 04 May 2012 15:06:43 -0700, bilsch wrote:

    > On 05/04/2012 07:11 AM, Leif Roar Moldskred wrote:
    >> bilsch<> wrote:
    >>
    >>
    >>> Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    >>> Offending program, Nvr1.java is in directory:
    >>>
    >>> /home/bilsch/NetBeansProjects/NVRAM/src/
    >>>
    >>> environment variable PATH is:
    >>>
    >>> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/

    usr/bin:/sbin:/bin:/usr/games
    >>
    >> And there's your problem -- your PATH does not contain the directory
    >> your java and javac commands are found in, neither as an explicit entry
    >> of /home/bilsch/jdk7/bin/ or implicitly through the current directory .
    >>
    >>> However note that when I run; java Nvr1.class (or simply Nvr1) from my
    >>> home directory the output errors are in javanese, as follows:
    >>>
    >>> bilsch@p4pwj:~/jdk7/bin$ java Nvr1 Exception in thread "main"
    >>> java.lang.NoClassDefFoundError: Nvr1 Caused by:
    >>> java.lang.ClassNotFoundException: Nvr1

    >>
    >> You're running a java command here, but not the one at
    >> /home/bilsch/jdk7/bin/java -- you must have another java command in
    >> your system somewhere. (Try the command "which java" to show where the
    >> java command that's actually being run is.)
    >>
    >> The solution is to add the directory /home/bilsch/jdk7/bin/ to the
    >> front of your PATH. Write the following command on the command line:
    >>
    >> export PATH=/home/bilsch/jdk7/bin/:$PATH
    >>
    >> You should then be able to call javac, use that to create a .class file
    >> and then use java to run the class file.
    >>
    >>

    > I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
    > run program Nvr1 from the command line. Also, when I then go into
    > NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
    > IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
    > /home/bilsch/jdk7/bin part has been removed. I even put the PATH change
    > in two different places in the PATH variable and both were removed. Does
    > anybody have a java IDE other than NetBeans ?
    >

    Look at where PATH is defined in the NetBeans configuration and change
    that.

    > Also, a pain in the ass is I must change directory to where the source
    > file resides to compile. I must change directory to where the .class
    > file resides in order to run. These directories are different for every
    > project therefore it's not practical to automate with a script.
    >

    Either use Ant (write a build.xml file if you can't use the one that
    NetBeans uses) and/or write a shell script to run the compile from the
    correct directory.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, May 5, 2012
    #15
  16. bilsch

    Lew Guest

    bilsch wrote:
    > Also, a pain in the ass is I must change directory to where the source
    > file resides to compile. I must change directory to where the .class
    > file resides in order to run. These directories are different for every
    > project therefore it's not practical to automate with a script.


    That is totally untrue.

    Both the compiler ("javac") and the runtime ("java") respect classpaths,
    and the latter respects source paths. With those, you can compile and run
    Java code from any directory regardless of your current directory.

    Please, please, please, please, *please* RTFM!

    Especially before you start ranting incorrectly about what is not possible.

    Why did you ignore the earlier advice to do that?

    --
    Lew
     
    Lew, May 5, 2012
    #16
  17. On Fri, 04 May 2012 19:48:14 -0500, Leif Roar Moldskred wrote:

    > This isn't a problem with NetBeans, but has to do with how environment
    > variables work. An "export" statement only sets an environment variable
    > for the current shell. To have the change stick, you need to put the
    > addition to PATH in a configuration file (most likely ~/.profile, but
    > some linux distroes can be a little weird about it) so that it will be
    > set for every shell you open.
    >

    In the Redhat family of distros you can make this sort of change by
    putting a script in /etc/profile.d

    Scripts in profile.d are run after /etc/profile so I have one called
    java.sh which sets all my Java-related environment variables, e.g.
    JAVA_HOME, ANT_HOME and uses the pathmunge shell function to add /usr/
    java/sdk/bin and /usr/java/ant/bin to $PATH

    I make a lot of use symlinks: /usr/java is a symlink to /home/java so my
    Java set-up will survive a system reinstall. /home is in a separate
    partition that isn't reformatted during an install.

    Inside the /home/java directory, jdk is a symlink to the current Java SDK
    install and ant is a symlink to the current Ant install. This means that
    the contents of /etc/profile.d/java.sh doesn't change when I install a
    new version of the JDK: I merely switch the sdk symlink at the same time
    as I unpack the download.

    >> Also, a pain in the ass is I must change directory to where the source
    >> file resides to compile. I must change directory to where the .class
    >> file resides in order to run.

    >
    > You don't have to do either of these. I suggest you follow Lew's
    > suggestion and read the documentation for the java and javac commands.
    >

    Seconded.

    >> These directories are different for every
    >> project therefore it's not practical to automate with a script.

    >

    If you take the time to set your system up appropriately everything will
    'just work'.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, May 5, 2012
    #17
  18. bilsch

    bilsch Guest

    On 05/04/2012 04:06 PM, Martin Gregorie wrote:
    > On Fri, 04 May 2012 15:06:43 -0700, bilsch wrote:
    >
    >> On 05/04/2012 07:11 AM, Leif Roar Moldskred wrote:
    >>> bilsch<> wrote:
    >>>
    >>>
    >>>> Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    >>>> Offending program, Nvr1.java is in directory:
    >>>>
    >>>> /home/bilsch/NetBeansProjects/NVRAM/src/
    >>>>
    >>>> environment variable PATH is:
    >>>>
    >>>> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/

    > usr/bin:/sbin:/bin:/usr/games
    >>>
    >>> And there's your problem -- your PATH does not contain the directory
    >>> your java and javac commands are found in, neither as an explicit entry
    >>> of /home/bilsch/jdk7/bin/ or implicitly through the current directory .
    >>>
    >>>> However note that when I run; java Nvr1.class (or simply Nvr1) from my
    >>>> home directory the output errors are in javanese, as follows:
    >>>>
    >>>> bilsch@p4pwj:~/jdk7/bin$ java Nvr1 Exception in thread "main"
    >>>> java.lang.NoClassDefFoundError: Nvr1 Caused by:
    >>>> java.lang.ClassNotFoundException: Nvr1
    >>>
    >>> You're running a java command here, but not the one at
    >>> /home/bilsch/jdk7/bin/java -- you must have another java command in
    >>> your system somewhere. (Try the command "which java" to show where the
    >>> java command that's actually being run is.)
    >>>
    >>> The solution is to add the directory /home/bilsch/jdk7/bin/ to the
    >>> front of your PATH. Write the following command on the command line:
    >>>
    >>> export PATH=/home/bilsch/jdk7/bin/:$PATH
    >>>
    >>> You should then be able to call javac, use that to create a .class file
    >>> and then use java to run the class file.
    >>>
    >>>

    >> I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
    >> run program Nvr1 from the command line. Also, when I then go into
    >> NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
    >> IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
    >> /home/bilsch/jdk7/bin part has been removed. I even put the PATH change
    >> in two different places in the PATH variable and both were removed. Does
    >> anybody have a java IDE other than NetBeans ?
    >>

    > Look at where PATH is defined in the NetBeans configuration and change
    > that.

    I can't find any place where path is defined in NetBeans. They told me
    two ways to change PATH outside of NetBeans. I did that.
    >
    >> Also, a pain in the ass is I must change directory to where the source
    >> file resides to compile. I must change directory to where the .class
    >> file resides in order to run. These directories are different for every
    >> project therefore it's not practical to automate with a script.
    >>

    > Either use Ant (write a build.xml file if you can't use the one that
    > NetBeans uses) and/or write a shell script to run the compile from the
    > correct directory.


    I have an ANT directory and a tab for it in NetBeans but I dont know if
    it is installed. Same goes for Maven. I tried starting it on the
    command line ant there it says to install it.
    >
    >
     
    bilsch, May 5, 2012
    #18
  19. bilsch

    bilsch Guest

    On 05/04/2012 04:06 PM, Martin Gregorie wrote:
    > On Fri, 04 May 2012 15:06:43 -0700, bilsch wrote:
    >
    >> On 05/04/2012 07:11 AM, Leif Roar Moldskred wrote:
    >>> bilsch<> wrote:
    >>>
    >>>
    >>>> Programs java and javac are in directory: /home/bilsch/jdk7/bin/
    >>>> Offending program, Nvr1.java is in directory:
    >>>>
    >>>> /home/bilsch/NetBeansProjects/NVRAM/src/
    >>>>
    >>>> environment variable PATH is:
    >>>>
    >>>> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/

    > usr/bin:/sbin:/bin:/usr/games
    >>>
    >>> And there's your problem -- your PATH does not contain the directory
    >>> your java and javac commands are found in, neither as an explicit entry
    >>> of /home/bilsch/jdk7/bin/ or implicitly through the current directory .
    >>>
    >>>> However note that when I run; java Nvr1.class (or simply Nvr1) from my
    >>>> home directory the output errors are in javanese, as follows:
    >>>>
    >>>> bilsch@p4pwj:~/jdk7/bin$ java Nvr1 Exception in thread "main"
    >>>> java.lang.NoClassDefFoundError: Nvr1 Caused by:
    >>>> java.lang.ClassNotFoundException: Nvr1
    >>>
    >>> You're running a java command here, but not the one at
    >>> /home/bilsch/jdk7/bin/java -- you must have another java command in
    >>> your system somewhere. (Try the command "which java" to show where the
    >>> java command that's actually being run is.)
    >>>
    >>> The solution is to add the directory /home/bilsch/jdk7/bin/ to the
    >>> front of your PATH. Write the following command on the command line:
    >>>
    >>> export PATH=/home/bilsch/jdk7/bin/:$PATH
    >>>
    >>> You should then be able to call javac, use that to create a .class file
    >>> and then use java to run the class file.
    >>>
    >>>

    >> I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
    >> run program Nvr1 from the command line. Also, when I then go into
    >> NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
    >> IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
    >> /home/bilsch/jdk7/bin part has been removed. I even put the PATH change
    >> in two different places in the PATH variable and both were removed. Does
    >> anybody have a java IDE other than NetBeans ?
    >>

    > Look at where PATH is defined in the NetBeans configuration and change
    > that.
    >
    >> Also, a pain in the ass is I must change directory to where the source
    >> file resides to compile. I must change directory to where the .class
    >> file resides in order to run. These directories are different for every
    >> project therefore it's not practical to automate with a script.
    >>

    > Either use Ant (write a build.xml file if you can't use the one that
    > NetBeans uses) and/or write a shell script to run the compile from the
    > correct directory.
    >
    >

    I'm not too handy with shell programming.
     
    bilsch, May 5, 2012
    #19
  20. bilsch

    bilsch Guest

    On 05/05/2012 08:02 AM, Martin Gregorie wrote:
    > On Fri, 04 May 2012 19:48:14 -0500, Leif Roar Moldskred wrote:
    >
    >> This isn't a problem with NetBeans, but has to do with how environment
    >> variables work. An "export" statement only sets an environment variable
    >> for the current shell. To have the change stick, you need to put the
    >> addition to PATH in a configuration file (most likely ~/.profile, but
    >> some linux distroes can be a little weird about it) so that it will be
    >> set for every shell you open.
    >>

    > In the Redhat family of distros you can make this sort of change by
    > putting a script in /etc/profile.d
    >
    > Scripts in profile.d are run after /etc/profile so I have one called
    > java.sh which sets all my Java-related environment variables, e.g.
    > JAVA_HOME, ANT_HOME and uses the pathmunge shell function to add /usr/
    > java/sdk/bin and /usr/java/ant/bin to $PATH
    >
    > I make a lot of use symlinks: /usr/java is a symlink to /home/java so my
    > Java set-up will survive a system reinstall. /home is in a separate
    > partition that isn't reformatted during an install.
    >
    > Inside the /home/java directory, jdk is a symlink to the current Java SDK
    > install and ant is a symlink to the current Ant install. This means that
    > the contents of /etc/profile.d/java.sh doesn't change when I install a
    > new version of the JDK: I merely switch the sdk symlink at the same time
    > as I unpack the download.
    >


    It is interesting and I grasp the concepts but actually doing those
    things myself is beyond me.

    >>> Also, a pain in the ass is I must change directory to where the source
    >>> file resides to compile. I must change directory to where the .class
    >>> file resides in order to run.

    >>
    >> You don't have to do either of these. I suggest you follow Lew's
    >> suggestion and read the documentation for the java and javac commands.
    >>

    > Seconded.
    >

    I can't find any documentation for command line java and javac.

    >>> These directories are different for every
    >>> project therefore it's not practical to automate with a script.

    >>

    > If you take the time to set your system up appropriately everything will
    > 'just work'.
    >
    >
     
    bilsch, May 5, 2012
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tomas Penc
    Replies:
    3
    Views:
    36,110
  2. cppaddict
    Replies:
    2
    Views:
    464
    Roedy Green
    May 9, 2004
  3. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    694
  4. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    616
    Cameron Simpson
    Sep 22, 2008
  5. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    628
    Fredrik Lundh
    Sep 22, 2008
Loading...

Share This Page