Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > my java is broken !

Reply
Thread Tools

my java is broken !

 
 
bilsch
Guest
Posts: n/a
 
      04-29-2012
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");
}

}
}
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      04-29-2012
bilsch <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
bilsch
Guest
Posts: n/a
 
      04-29-2012
On 04/29/2012 05:26 AM, Stefan Ram wrote:
> bilsch<(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-29-2012
On Sun, 29 Apr 2012 05:36:32 -0700, bilsch <(E-Mail Removed)>
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.
..
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      04-29-2012
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
 
Reply With Quote
 
bilsch
Guest
Posts: n/a
 
      04-29-2012
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.
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      04-29-2012
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
 
Reply With Quote
 
bilsch
Guest
Posts: n/a
 
      05-03-2012
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.ja va:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:48
at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.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.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-03-2012
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.ja va:2442)
> at java.lang.Class.getMethod0(Class.java:2685)
> at java.lang.Class.getMethod(Class.java:1620)
> at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:48
> at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.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
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      05-03-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are "broken iterators" broken? Steven D'Aprano Python 8 09-28-2008 09:19 PM
Re: Why are "broken iterators" broken? Fredrik Lundh Python 0 09-22-2008 04:32 PM
Re: Why are "broken iterators" broken? Cameron Simpson Python 0 09-22-2008 04:32 AM
PDM broken after Java update Cisco Fan Cisco 1 04-21-2005 03:13 PM
terrible java.net.SocketException: Broken pipe, please HELP!! Tomas Penc Java 3 10-24-2003 09:22 AM



Advertisments